好的,所以我尝试将文档中的所有斜体替换为“ %text%”:
Sub Italic()
Set oFound = ActiveDocument.Content
With oFound.Find
.ClearFormatting
.Text = ""
.Font.Italic = True
.Replacement.Text = "<i>" + %something here% + "</i>"
.Execute Replace:=wdReplaceAll
End With
End Sub
我想我需要找出如何引用找到的文本的方法:%something here%??也许还有另一种方法?
答案 0 :(得分:1)
要查找所有斜体文本并将其替换为自身,以及使用特殊字符^&
之前和之后的文本作为替换文本字符串的一部分。例如:
Sub TestReplaceInItalic()
Dim replaceText As String
replaceText = "%^&%"
With ActiveDocument.content.Find
.ClearFormatting
.Format = True
.Font.Italic = True
.Text = ""
.Replacement.Text = replaceText
.Execute Replace:=wdReplaceAll
End With
End Sub