VBA (Visual Basic for Applications) is a programming language that allows users to automate tasks in Microsoft Office applications, including Outlook. One common task is pasting plain text into the body of an Outlook email. This article will guide entry-level users on how to accomplish this using VBA.
Step 1: Open the Visual Basic Editor
To begin, open Outlook and press ALT + F11 on your keyboard. This will open the Visual Basic Editor.
Step 2: Create a New Module
In the Visual Basic Editor, click on Insert and then select Module. This will create a new module where we can write our VBA code.
Step 3: Write the VBA Code
In the newly created module, paste the following VBA code:
Sub PastePlainText()
Dim objOL As Outlook.Application
Dim objDoc As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
Set objDoc = objOL.CreateItem(olMailItem)
objDoc.Display
objDoc.GetInspector.WordEditor.Range.Text = Application.ClipboardText
End Sub
This code creates a new Outlook email and pastes the plain text from the clipboard into the email body.
Step 4: Save and Test the Macro
Click on File and then select Save to save the macro. Give it a name, such as "PastePlainText".
To test the macro, press F5 on your keyboard or click on the Run button in the toolbar. This will execute the macro and open a new Outlook email with the plain text from the clipboard pasted into the body.
Step 5: Assign a Shortcut Key (Optional)
If you want to quickly access this macro, you can assign a shortcut key to it. To do this, go back to Outlook and click on File, then select Options.
In the Outlook Options window, click on Customize Ribbon on the left-hand side. Then, click on the Customize... button next to Keyboard Shortcuts.
In the Customize Keyboard window, select Macros from the Categories list. You should see your macro listed in the Commands list. Click on it and then choose a shortcut key combination in the Press new shortcut key field.
Once you've chosen a shortcut key, click on the Assign button and then click Close to save the changes. Now you can use the assigned shortcut key to run the macro.
By following these steps, entry-level users can easily create a VBA macro to paste plain text into the body of an Outlook email. This can be a time-saving solution for those who frequently need to remove formatting from copied text before sending it via email.
References
| Reference | Link |
|---|---|
| Microsoft VBA Documentation | https://docs.microsoft.com/en-us/office/vba/api/overview/outlook |
| Outlook VBA Reference | https://docs.microsoft.com/en-us/office/vba/api/outlook |
| How to Assign a Shortcut Key to a Macro | https://www.howtogeek.com/409802/how-to-assign-a-shortcut-key-to-a-macro-in-excel/ |