I’m trying to generate a draft email using VBA code from excel file.
I’m stuck from adding the default signature and maintains its format. My current code can add the signature but the format has been changed. What should I need to change to capture the exact format of signature, I tried the .Display and used the .HTMLBody but the the signature doesn’t shown up but some hyperlink which I do not understand where coming from.
Here’s my current code:
Sub DraftEmail()
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim lCounter As Long
Dim signature As String
'Set objects
Set objOutlook = Outlook.Application
'Show confirmation message to user
MsgBox "Draft Email Generated.", vbInformation
'Create a new draft email
Set objMail = objOutlook.CreateItem(olMailItem)
objMail.Display
signature = objMail.Body
'Read details from Draft Email Sheet
For lCounter = 6 To 6
'To
objMail.To = Worksheets("Draft Email").Range("A" & lCounter).Value
'Cc
objMail.CC = Worksheets("Draft Email").Range("B" & lCounter).Value
'Subject
objMail.Subject = Worksheets("Draft Email").Range("C" & lCounter).Value
'Draft Email Body
objMail.Body = Worksheets("Draft Email").Range("D" & lCounter).Value & objMail.Body
'Add Attachment
'objMail.Attachments.Add (Draft Email.Range("E" & lCounter).Value)
'Close the object
Set objMail = Nothing
Next
End Sub
Thanks in advance! 🙂
2
Answers
Appears
Dim signature As String
is the source of the confusion.You can append the signature without a signature variable.