新替换的超链接丢失格式(word->外观) [英] formatting lost for new replaced hyperlinks(word->outlook)
问题描述
我写了一段代码,将某种格式的文本替换为超链接.规则在传入电子邮件期间调用此代码.
收到的电子邮件->将电子邮件复制到单词编辑器->进行必要的更改->从单词编辑器复制到Outlook邮件项目(替换的超链接在邮件项目中丢失,而新添加的文本保留原样)
我的代码在这里供您参考..
I have written a code which replaces the text of certain format into a hyperlink. This code is invoked by a rule during an Incoming email.
Incoming email -> copy the email to word editor -> make necessary changes -> copy from word editor to outlook mail item(replaced hyperlinks gets lost in mail item, while newly added text reamins intact)
My code is here for your refernce..
Sub IncomingHyperlink(MyMail As MailItem)
Dim strID As String
Dim Body As String
Dim objMail As Outlook.MailItem
Dim myObject As Object
Dim myDoc As Word.Document
Dim mySelection As Word.Selection
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
''Creates word application
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
''Copies contents of email into word document
objSelection.TypeText "GOOD" & objMail.HTMLBody
With objSelection.Find
.ClearFormatting
.Text = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
.Forward = True
.Wrap = wdFindAsk
.MatchWildcards = True
End With
objSelection.Find.Execute
objSelection.Hyperlinks.Add Anchor:=objSelection.Range, _
Address:="http://www.code.com/" & objSelection.Text, _
TextToDisplay:=objSelection.Text
''Copies contents to email item from word document
objMail.HTMLBody = objDoc.Range(0, objDoc.Range.End)
objMail.Save
Set objMail = Nothing
End Sub
此外,此代码仅替换第一次出现的所需文本,而不替换其他文本.
请帮助解决这些问题.谢谢...
我尝试了其他选项,但仍然无法正常工作.
Also, this code replaces only the first occurrence of the needed text and does not replace others.
Please help solve these problems. Thank you...
I have tried out different options and still not able to get it work.
推荐答案
您需要循环执行,直到Execute()为true.
You need to loop until Execute() is true.
Do while objSelection.Find.Execute()
'code to make changes in text
Loop
这篇关于新替换的超链接丢失格式(word->外观)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!