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

给你一囗甜甜゛ 提交于 2019-12-24 19:28:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20130422/vb-outlook-macro-how-to-put-variable-fields-in-an-email-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!