I wish to create a macro that inserts the date into an email body which is currently open for editing, prior to sending.
I am using Outlook 2013 on a Windows 7 machine.
Desired workflow:
(Assume the date has been stored as a string variable, i.e. the macro simply inserts a variable into the email body at a desired position).
All Outlook VBA examples I have found for inserting text into an email body involve storing the active email's HTMLBody as a string, appending the desired text to that string, then creating a brand new email, and re-populating the to, cc, bcc, subject and htmlbody. I wish to avoid this, as it seems very clunky.
Thank you in advance for your help.
InsertBefore Method or InsertAfter Method
Inspector.WordEditor Property (Outlook)
Application.ActiveInspector Method (Outlook)
Example
Option Explicit
Public Sub Example()
Dim Inspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim Selection As Word.Selection
Set Inspector = Application.ActiveInspector()
Set wdDoc = Inspector.WordEditor
Set Selection = wdDoc.Application.Selection
Selection.InsertBefore Format(Now, "DD/MM/YYYY")
Set Inspector = Nothing
Set wdDoc = Nothing
Set Selection = Nothing
End Sub
Reference to Microsoft Word xx.x Object Library
Go to Outlook VBA editor either by pressing
"Alt + F11"keys or clicking on the"Visual Basic"button in the “Developer” ribbon.
1. In VBA editor window, click the "Tools" button in the menu bar.
2. Then, from the drop down list, select the "References" option.
- 3. In the dialog box, you can pull the scrolling bar down until you locate what you want, such as "Microsoft Word XX.X Object Library".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With