Andrew Allen
Andrew Allen

Reputation: 8022

Edit table text within Outlook email

I want to be able to find and replace text within an email that has been embedded in a table using Excel VBA. I already know how to open the existing outlook email. From the forums I understand that the following code works for text only but not when it's embedded in a table within the email.

Is there any way to use bookmarks? Any attempt I've made leaves the email body untouched or strips all formatting.

With OutMail
    .To = UserForm1.TextBox4.Text
    .CC = ""
    .BCC = ""
    .Subject = "This is my Subject line"
    .HTMLBody = Replace(.HTMLBody, "<First Name>", UserForm1.TextBox5.Text)
    .HTMLBody = Replace(.HTMLBody, "<Last Name>", UserForm1.TextBox6.Text)
    .Display
End With

Upvotes: 0

Views: 2107

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49405

The Outlook uses Word as an email editor. You can use the Word object model to get the job done. The WordEditor property of the Inspector class returns an instance of the Word Document which represents the message body.

You can read more about all possible ways of working with item bodies in the Chapter 17: Working with Item Bodies.

Upvotes: 1

Related Questions