How to add HTML signature to email

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello Everyone:

I wrote the code below and it works great, however I need to add my signature to the email which contains some HTML as well. How can I add it? Also, let me know if my code could be improved. Here is my code:

VBA Code:
Sub SendEmailAttachment()


Dim Email As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim attachment2 As String
Dim x As Integer


 x = 2

Do While Sheet1.Cells(x, 1) <> ""
   
    Set outlookapp = CreateObject("Outlook.Application")
    Set outlookmailitem = outlookapp.CreateItem(0)
    Set myAttachments = outlookmailitem.Attachments
    path = "C:\Statements\"
    Email = Sheet1.Cells(x, 1)
      
    subj = Sheet1.Cells(x, 2)
    filename = Sheet1.Cells(x, 3)
    attachment = path + filename
    attachment2 = path + "CEO Letter to Employees.Pdf"


    
        outlookmailitem.To = Email
        outlookmailitem.cc = ""
        outlookmailitem.bcc = ""
        outlookmailitem.Subject = subj
        outlookmailitem.body = "Please find your statement attached" & vbCrLf & "Best Regards"
           
            
        myAttachments.Add (attachment)
        myAttachments.Add (attachment2)
        outlookmailitem.Display
        outlookmailitem.send
            
        lastrow = lastrow + 1
        Email = ""
    x = x + 1

Loop


Set outlookapp = Nothing
Set outlookmailitem = Nothing

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If you already have a signature defined, so that it appears automatically in your emails, use this and it will be kept:

VBA Code:
        outlookmailitem.HTMLbody = "Please find your statement attached<br><br>Best Regards<br><br>" & outlookmailitem.HTMLbody
 
Upvote 0

Forum statistics

Threads
1,215,825
Messages
6,127,111
Members
449,359
Latest member
michael2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top