替换HTML正文中的文本 [英] Replace text in HTML body

查看:165
本文介绍了替换HTML正文中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在替换已在Outlook 2010中创建的模板的正文中的文本。这样做的目的是让用户可以更加轻松地更新发送电子邮件的联系人。

I'm trying to replace text in the body of a template already created in Outlook 2010. The purpose of this is so that users can update the contact which the email is being sent to fairly easily.

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替换工作,但后来我失去了我的电子邮件的格式。我缺少什么?

The template opens up for review but no replacements have been made to the body of the email. If I use myItem.Body the replacement works but then I lose my formatting of my email. What am I missing?

推荐答案

我不知道如何标记或标记一个答案,但这里是代码我从Tim Williams提供的编辑工作中,感谢您的帮助:

I'm not sure how to tag or flag an answer for this but here is the code that I got to work from the editing provided by Tim Williams, thank you for your help with this:

Sub NewUserEmail()

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

这篇关于替换HTML正文中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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