I am trying to automate some emails using VBA for Excel. Everything so far is fine, except trying to keep my signature in the email.
Once you tell VBA to create a new email, it will already contain your default signature. This can be seen if you try Outmail.Display. However if you overwrite the .HTMLBody property, it will be deleted.
My simple attempt was to save the contents of .HTMLBody to a signature (string), and then reassign it to .HTMLBody just to test it out. However the resulting email will be void of any signature.
Code to copy and re-insert the signature:
Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Dim signature As String
Set myOlApp = CreateObject("Outlook.Application")
Set Outmail = myOlApp.CreateItem(0)
signature = Outmail.HTMLBody
Outmail.HTMLBody = signature
Outmail.Display
Code to show that signature is automatically inserted:
Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set Outmail = myOlApp.CreateItem(0)
Outmail.Display
Edit: I tried replacing .HTMLBody with .Body. That works, but obviously takes out the HTML formatting of the signature
Edit 2: The code works on my friend's computer but not on mine