VB、Outlook 宏:如何在电子邮件模板中放置变量(字段) [英] VB, Outlook Macro: How to put variable, (fields), in an email template

查看:76
本文介绍了VB、Outlook 宏:如何在电子邮件模板中放置变量(字段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的宏,可以从 .csv 文件中读取字符串.我想将(替换)这些字符串放入电子邮件正文中.电子邮件将从模板中打开,所以我想要模板中的字段,然后让我的宏从模板开始一封新电子邮件,并用字符串变量替换这些字段.

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.

参考链接会很有帮助.

故事的其余部分:电子邮件模板正文是从 Word 邮件合并文档粘贴的,因此它已经在正确的位置具有邮件合并字段.可能有一种方法可以让 Outlook 中的 mailmerge 工作,但是 Word 中的 mailmerge 有问题,我不知道是什么让 mailmerge 打勾,所以当它在用户的计算机上坏了时,我不得不重建合并文档,等等.现在我们正在切换到电子邮件而不是打印的 Word 文档,我更愿意编写宏来明确放置数据.我没有用 vba 做过很多编程,所以我会边走边学语法.

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.

推荐答案

没有字段.您的 Outlook .oft 模板应包含唯一的字符串占位符.

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

.CreateItemFromTemplate 后,替换唯一的字符串占位符.

Once you .CreateItemFromTemplate, replace the unique string placeholders.

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

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

您可能会进行某种循环.

You will likely work out some kind of loop.

这篇关于VB、Outlook 宏:如何在电子邮件模板中放置变量(字段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆