【发布时间】:2011-09-19 05:39:49
【问题描述】:
我正在尝试用模式 ASA####@@ 将正文中的文本替换为 ASA####@@(超链接)
如果正文中只有一种模式,我的代码可以工作。
但如果我有很多类似的模式
ASA3422df
ASA2389ds
ASA1265sa
整个身体被替换为
ASAhuyi65
我的代码在这里。
Dim strID As String
Dim Body As String
Dim objMail As Outlook.MailItem
Dim temp As String
Dim RegExpReplace As String
Dim RegX As Object
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
Body = objMail.HTMLBody
Body = Body + "Test"
objMail.HTMLBody = Body
Set RegX = CreateObject("VBScript.RegExp")
With RegX
.Pattern = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
.Global = True
.IgnoreCase = Not MatchCase
End With
'RegExpReplace = RegX.Replace(Body, "http://www.code.com/" + RegX.Pattern + "/ABCD")
'if the replacement is longer than the search string, future .FirstIndexes will be off
Offset = 0
'Set matches = RegX.Execute(Body)
For Each m In RegX.Execute(Body)
RegExReplace = "<a href=""http://www.code.com/" & m.Value & """>" & m.Value & "</a>"
Next
Set RegX = Nothing
objMail.HTMLBody = RegExReplace
objMail.Save
Set objMail = Nothing
End Sub
【问题讨论】: