Gene
Gene

Reputation: 91

VB, Outlook Macro: How to put variable, (fields), in an email template

I have a simple macro that reads Strings from a .csv file. I want to place (Replace) those Strings into the body of an email. The email will be opened from a template, so I want the fields in the template, and then have my macro start a new email from the template and replace the fields with the String variables.

I'm not finding anything posted that shows how to format such a field in the body of the email.

A link to a reference would be helpful.

The rest of the story: The email template body was pasted from a Word mailmerge document, so it already has mailmerge fields in the correct locations. There is probably a way to make mailmerge work in Outlook, but mailmerge in Word was problematic, and I don't know what makes mailmerge tick, so when it broke on a user's computer I had to rebuild the merge document, etc. Now we're switching to email instead of a printed Word document, and I'm more comfortable with writing a macro to explicitly place the data. I haven't done much programming in vba, so I'm picking up the syntax piece by piece as I go.

Upvotes: 1

Views: 3865

Answers (1)

niton
niton

Reputation: 9179

There are no fields. Your Outlook .oft template should contain unique string placeholders.

Once you .CreateItemFromTemplate, replace the unique string placeholders.

MyMail.HTMLBody = Replace(MyMail.HTMLBody, "UniqueStringPlaceholder_1", "csvstring_1")

You will likely work out some kind of loop.

Upvotes: 1

Related Questions