1 | initial version |
To insert an Outlook signature in an email using Excel VBA, you can use the following code:
Sub AddOutlookSignature()
Dim Signature As String
Dim OutlookApp As Outlook.Application
Dim Mail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set Mail = OutlookApp.CreateItem(olMailItem)
Signature = OutlookApp.EmailSignature
With Mail
.Display
.HTMLBody = Signature
End With
Set Mail = Nothing
Set OutlookApp = Nothing
End Sub
To send out an email automatically using Excel VBA, you can use the following code:
Sub SendEmail()
Dim OutlookApp As Outlook.Application
Dim Mail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set Mail = OutlookApp.CreateItem(olMailItem)
With Mail
.To = "recipientemailaddress@example.com"
.Subject = "Email subject"
.Body = "Email body"
.Send
End With
Set Mail = Nothing
Set OutlookApp = Nothing
End Sub
You can combine these two codes to insert the Outlook signature and send out the email automatically using Excel VBA as follows:
Sub SendEmailWithSignature()
Dim Signature As String
Dim OutlookApp As Outlook.Application
Dim Mail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set Mail = OutlookApp.CreateItem(olMailItem)
Signature = OutlookApp.EmailSignature
With Mail
.To = "recipientemailaddress@example.com"
.Subject = "Email subject"
.HTMLBody = Signature & "Email body"
.Send
End With
Set Mail = Nothing
Set OutlookApp = Nothing
End Sub