Consulting

Results 1 to 8 of 8

Thread: Including HTML Code in Email Body

  1. #1

    Including HTML Code in Email Body

    Hi Guys,

    I have included some prelim code that should send a HTML email that includes my company signature.

    However, it only generates the required signature if I add ".display" method before the .HTML body property within the "With Block".

    If I include .send method after .HTML property it strips the email of formatting and I include the .send method after the .HTML body it generates an error message.

    I am looking to retain the HTML formatting and the .display method - is this possible, please?
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    857
    Location
    You can have .Display just before the .Send as a simple workaround
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  3. #3
    Thank you for your reply, Georgiboy and thank for your help previously with other queries.

    When I add the .display method before the .send method the for loop will trigger and output and send one email but then stop and generate a run-time error: "Item has been moved or deleted"

    Please let me know if there is an alternative workaround

  4. #4
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    857
    Location
    How about if you add the below line of code under the .Display:
    DoEvents
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  5. #5
    Darnit - it is still flagging with the same run time error. Thank you for your help. So frustrating as I am really keen to retain the HTML formatting

  6. #6
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    857
    Location
    Google: ron de bruin send email keep signature vba

    Have a look at the first link that comes up - he is the master at automating Outlook via excel (IMO)
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  7. #7
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    857
    Location
    Here is another example where the signature is captured from the display before it is then sent with the signature:

    Sub test()    
        Dim OApp As Object, OMail As Object, signature As String
        
        Set OApp = CreateObject("Outlook.Application")
        
        For x = 1 To 5
            Set OMail = OApp.CreateItem(0)
            With OMail
                .Display
                DoEvents
            End With
            signature = OMail.HTMLBody
            With OMail
                .to = "jbloggs@somebusiness.com"
                .Subject = "Subject here"
                .HTMLBody = "Body text here" & vbNewLine & signature
                .Send
            End With
        Next x
        
        Set OMail = Nothing
        Set OApp = Nothing
    End Sub
    Last edited by georgiboy; 06-17-2022 at 08:03 AM.
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  8. #8
    No. I think you are the master. The sample code you have provided is amazing and works.

    Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •