在vba中进行条件搜索

时间:2017-01-28 16:29:30

标签: vba search conditional highlight

这是查找并突出显示Word文档中某些单词的实例。 在以下代码的TargetList中,如何插入这些单词: 1.“^ $” 2.“^#然而” 3.“^ $”

(我的意思是,条件搜索;例如,搜索“任何字母”“空格”“然而”组合的实例。) 提前谢谢。

Sub HighlightTargets2()

Dim range As range
Dim i As Long
Dim TargetList

TargetList = Array("asset and liability method", "auditor's", "Black Scholes", "comprised of", "comprised primarily of", "primarily comprised of", "defined benefit", "defined contribution", "effected", "effecting", "effective interest method", "effective interest rate method", "footnote", "high quality", "however ", "in the U.S.", "in the us", "kmpg", "kpgm", "kgpm", "lump sum", "manger", "more likely than not recognition", "more likely than not threshold", "multi-", "non-", "option-pricing", "payer", "percentage of completion method", "percentage of completion accounting", "polices", "post-", "pro-", "proforma", "re-", "related party transaction", "respectively ", "^# respectively", "respectfully", "revenues", "see note", "see footnote", "self insurance", "Self insured", "stop loss", "straight line basis", "straight line method", "the this", "the a", "third party transaction", "website", "-wide", " wide", "year end")

For i = 0 To UBound(TargetList)

Set range = ActiveDocument.range

With range.Find
.Text = TargetList(i)
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute(Forward:=True) = True
range.HighlightColorIndex = wdYellow

Loop

End With
Next

End Sub

0 个答案:

没有答案