通过替换VBA中的文本来编辑本地保存的.msg主体
下午好,
我有一个Outlook .msg电子邮件保存在计算机上的本地文件夹中。
有什么办法可以用我想要的VBA中任何一个单词替换体内“ AAAA”一词? 有什么办法可以将其更改为:字段?
目的是运行一个Excel表并创建模板消息的副本,将其替换为:字段和模板的某些单词,并在Excel表中使用信息并保存。我们将手动发送后者。
我只需要.msg文件修改代码(到:字段和身体替换)。循环已经编码。
太感谢了,
Good afternoon,
I have an Outlook .msg email saved at a local folder in my computer.
Is there any way I can replace the word "AAAA" in the body with any word I want in VBA?
Is there any way I can change the To: field?
The goal is to run an Excel table and create copies of a template message, replace the To: field and some words of the template with the info in the Excel table and save it. We will manually send latter.
I only need the .msg file modifying code (To: field and body replaces). The loop is already coded.
Thank you so much,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Outlook Object模型没有提供任何包装盒中编辑MSG文件的任何内容。但是,您可以自动化Outlook创建项目,对其进行编辑,然后将其保存为模板。
使用”来自Outlook模板(.oft)的新的Microsoft Outlook项目,并返回新项目。因此,您可以根据保存在磁盘上的模板创建一个新项目,然后更换所需的所有内容。然后,您可以将其保存为模板或将项目发送出去。在如何:基于模板创建新的Outlook消息文章。
The Outlook object model doesn't provide anything to edit MSG files out of the box. But you can automate Outlook to create an item, edit it and then save it back as a template.
Use the Application.CreateItemFromTemplate method which creates a new Microsoft Outlook item from an Outlook template (.oft) and returns the new item. So, you can create a new item based on the template saved on the disk and then replace everything you need there. Then you could save it back as a template or send the item out. Read more about that in the How To: Create a new Outlook message based on a template article.
您可以使用
application.session.session.opensharedItem
打开MSG文件,修改返回的mailItem
Object(主题
/code>/htmlbody
/收件人
),然后调用mailItem.save
以更新MSG文件。You can use
Application.Session.OpenSharedItem
to open an MSG file, modify the returnedMailItem
object (Subject
/HTMLBody
/Recipients
), then callMAilItem.Save
to update the MSG file.如果有人需要,这是我使用的代码。不要专注于for循环,而要以加载,编辑和保存的味精的方式。
在此示例中,MSG文件中的某些单词被替换为Excel表中的值以及TO :(电子邮件接收器)。例如,MSG文件中的单词AA随C7单元格的值而更改。
目的是将MSG创建为具有一些关键词(AA,BB,CC等)的模板,复制该模板,将这些单词替换为Excel表中的单词并保存新的MSG文件。
If anyone needs, here it is the code I used. Do not focus on the for loops, but in the way the msg is loaded, edited and saved.
In this example some words in the msg file are replaced for the values in an excel table, as well as the TO: (email receiver). e.g. word AA in a msg file is changed with the value of the C7 cell.
The aim is to create a msg as a template with some key words (AA, BB, CC, etc), copy that template, replace those words with the ones in the excel table and save the new msg file.