我正在尝试替换已在Outlook 2010中创建的模板正文中的文本。这样做的目的是让用户可以非常轻松地更新发送电子邮件的联系人。
Sub NewUserEmail()
Dim myItem As Outlook.MailItem
Dim strContact As String
Dim strCompanyName As String
Dim strHTML As String
Set myItem = Application.CreateItemFromTemplate( _
"C:\Users\jim.reagan\AppData\Roaming\Microsoft\Templates\NewUserEmail.oft")
strHTML = myItem.HTMLBody
strContact = InputBox("What is the Contact's name?")
myItem.HTMLBody = Replace(myItem.HTMLBody, "%<Contact>%", strContact)
myItem.Display
End Sub
模板打开以供审核,但未对电子邮件正文进行替换。如果我使用myItem.Body替换工作,但后来我丢失了我的电子邮件格式。我错过了什么?
答案 0 :(得分:2)
我不确定如何标记或标记答案,但这是我从Tim Williams提供的编辑中得到的代码,感谢您对此的帮助:
Sub NewUserEmail()
Dim myItem As Outlook.MailItem
Dim strContact As String
Dim strCompanyName As String
Dim strHTML As String
Set myItem = Application.CreateItemFromTemplate("C:\file location\file.oft")
strHTML = myItem.HTMLBody
strContact = InputBox("What is the Contact's name?")
myItem.HTMLBody = Replace(myItem.HTMLBody, "%CONTACT%", strContact)
myItem.Display
End Sub