0
votes

Based off several resources, I have the following Excel VBA code to send an email from Outlook:

Sub SendEmail()
Dim OA As Object
Dim msg As Object

Set OA = CreateObject("Outlook.Application")
Set msg = OA.CreateItem(0)

sig = msg.HtmlBody
                   
msg.To = "[email protected]"
msg.Subject = "Subject Line!"
msg.HtmlBody = "<p>Body</p>" & sig
msg.Send
End Sub

However, my email signature is not being added to the end of the email body.

1

1 Answers

0
votes

Try to save the mail item to get the signature added:

Sub SendEmail()
  Dim OA As Object
  Dim msg As Object

  Set OA = CreateObject("Outlook.Application")
  Set msg = OA.CreateItem(0)
  sig = msg.HtmlBody

  msg.To = "[email protected]"
  msg.Subject = "Subject Line!"
  msg.HtmlBody = "<p>Body</p>" & sig

  msg.Display()

  msg.Send
End Sub

Also, you must set a well-formed HTML markup to the HTMLBody property. That means you have to find the starting <body> tag and insert your text there right after it.