-1

I have been trying to create an automailer in excel but the signature does not come up when I try to send it out. This is the VB script:

Sub Send_email_fromexcel()
    Dim OApp As Outlook.Application, outlookmailitem As Outlook.MailItem, signature As String
    Dim edress As String
    Dim subj As String
    Dim message As String
    Dim filename As String
    Dim OApp As Object
    Dim outlookmailitem As Object
    Dim signature As String
    Dim myAttachments As Object
    Dim path As String
    Dim lastrow As Integer
    Dim attachment As String
    Dim x As Integer
     
     
     
     
     x = 2
    
    Do While Sheet1.Cells(x, 1) <> ""
       
        Set OApp = CreateObject("Outlook.Application")
        Set outlookmailitem = OApp.createitem(0)
        Set myAttachments = outlookmailitem.Attachments
        path = "H:\Marketing\"
    
        edress = Sheet1.Cells(x, 1)
        cc = Sheet1.Cells(x, 3)
        subj = Sheet1.Cells(x, 4)
        filename = Sheet1.Cells(x, 5)
        body = Sheet1.Cells(x, 6)
        attachment = path + filename
        signature = outlookmailitem.body
        
    'With outlookmailitem
            outlookmailitem.To = edress
            outlookmailitem.cc = cc
            outlookmailitem.bcc = ""
            outlookmailitem.Subject = subj
            myAttachments.Add (attachment)
            outlookmailitem.display
            outlookmailitem.body = body & vbNewLine & signature
    
            
            
           ' outlookmailitem.send
                
            lastrow = lastrow + 1
            edress = ""
        x = x + 1
    Loop
    Set OApp = Nothing
    Set outlookmailitem = Nothing
    
End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Where does `Sheet1` come from, you have no object reference for `Sheet1` and you don't instantiate an instance of Excel? – user692942 Feb 07 '22 at 17:27
  • Does this answer your question? [How to add default signature in Outlook](https://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook) – niton Feb 07 '22 at 18:43

1 Answers1

0

In the code you are using a plain text string which represents a message body:

signature = outlookmailitem.body
'...
outlookmailitem.body = body & vbNewLine & signature

Most probably you wanted to use the HTMLBody property which returns or sets a string representing the HTML body of the specified item. Setting the HTMLBody property will always update the Body property immediately.

Also you may try to call the Display method before getting the signature from the message body.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45