【发布时间】:2018-10-03 14:28:22
【问题描述】:
我正在 Microsoft Word 中生成一些安全报告 - 导入 SOAP xml 请求和响应...
我想尽可能地自动化这个过程,并且我需要在这些请求/响应中突出显示一些文本。怎么做?一般来说,我需要突出显示请求中的非标准输入(每次都不同 - 错误的数据类型等)和响应中的错误字符串(大多数看起来像这样<faultstring>some error</faultstring>)。
这是我正在尝试的代码:
Sub BoldBetweenQuotes()
' base for a quotes finding macro
Dim blnSearchAgain As Boolean
' move to start of doc
Selection.HomeKey Unit:=wdStory
' start of loop
Do
' set up find of first of quote pair
With Selection.Find
.ClearFormatting
.Text = "<faultstring>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
' switch on selection extend mode
Selection.Extend
' find second quote of this pair
Selection.Find.Text = "</faultstring>"
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveLeft Unit:=wdCharacter, Count:=Len(Selection.Find.Text)
' make it bold
Selection.Font.Bold = True
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveRight Unit:=wdCharacter, Count:=1
blnSearchAgain = True
Else
blnSearchAgain = False
End If
Else
blnSearchAgain = False
End If
Loop While blnSearchAgain = True
End Sub
它仅突出显示第一个故障字符串,但其他外观保持未格式化我不知道为什么....感谢您的回复。
【问题讨论】:
标签: vba ms-word highlighting