Outlook VBA丢失具有替换功能和.HTMLBody的格式将不起作用 [英] Outlook VBA losing formatting with replace function and .HTMLBody won't work

查看:279
本文介绍了Outlook VBA丢失具有替换功能和.HTMLBody的格式将不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我随意搜索了站点的Outlook VBA堆栈溢出部分,但找不到与此问题相关的任何内容.我有一个创建的模板.当我打开模板时,格式已经是我想要的格式,并且签名自动填充在消息末尾.我创建了一个宏,提示您输入以下信息,然后用在输入框"中输入的信息替换消息中的标签.

I took the liberty of scouring the Outlook VBA stack overflow section of the site, and could not find anything related to this question. I have a template I created. When I open the template the formatting is already as I want it and the signature auto-populates at the end of the message. I have created a macro that prompts for the following information and then replaces my tags in the message with the information I entered in Input Boxes.

使用Google(很多)后,我尝试在我的替换函数中使用myItem.Body.当我这样做时宏可以工作,但我会丢失所有模板和签名格式.然后,我尝试在我的replace函数中使用myItem.HTMLBody,它不会替换正文中的任何内容,并且签名消失.

After using Google (a LOT) I tried using myItem.Body in my replace function. When I do this the macro works but I lose all template and signature formatting. Then I tried using myItem.HTMLBody in my replace function and it does not replace anything in the body and the signature disappears.

以下代码...任何指导将不胜感激. (Outlook 2010)

Code below... any guidance would be greatly appreciated. (Outlook 2010)

Sub PopulateTemplate()
Dim myItem As MailItem, oInspector As Inspector
Set oInspector = Application.ActiveWindow
Set myItem = oInspector.CurrentItem

'Provide the email address(es) and populate in the To field
strEmailAddr = InputBox("Enter email address(es), separated by semicolon(;)")
myItem.To = Replace(myItem.To, "<EmailAddr>", strEmailAddr)
myItem.Display

'Provide the project name and populate in subject and body of email
strProjName = InputBox("Enter the Project Name")
myItem.Subject = Replace(myItem.Subject, "<ProjectName>", strProjName)
myItem.Body = Replace(myItem.Body, "<ProjectName>", strProjName)
myItem.Display

'Provide the time of day for the greeting and populate in the body of email
strTimeofDay = InputBox("Enter Morning, Afternoon, or Evening")
myItem.Body = Replace(myItem.Body, "<TimeofDay>", strTimeofDay)
myItem.Display

'Provide the first name for the greeting and populate in body of email
strContactName = InputBox("Enter the First Name for the Greeting")
myItem.Body = Replace(myItem.Body, "<ContactName>", strContactName)
myItem.Display

'Resolve all recipients (Same as pressing the "Check Names" button)
Call myItem.Recipients.ResolveAll

'Free memory
Set strEmailAddr = Nothing
Set strProjName = Nothing
Set strTimeofDay = Nothing
Set strContactName = Nothing
End Sub

推荐答案

您的HTML正文中不会包含<"和>"文本字符(如"<ProjectName>"),它们将采用HTML编码-&lt;&gt;

Your HTML body would not have "<" and ">" text characters (as in "<ProjectName>"), they will be HTML encoded - &lt; and &gt;

这篇关于Outlook VBA丢失具有替换功能和.HTMLBody的格式将不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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