我想我会分享以下内容,因为它要么是vba功能,要么是我做错了。
我想找到整字,所以我设置了选择标志Selection.Find.MatchWholeWord = True
以下代码不会将MatchWholeWord的设置保留为True。它确实如此,但随后删除了第二个"中的设置"块
With Selection.Find
.ClearFormatting
.Forward = True
.Format = True
.MatchCase = True <-------------
.MatchWildcards = False
.MatchWholeWord = True <=============
.Replacement.ClearFormatting
.Replacement.Text = "^&"
.Replacement.Highlight = True
End With
For Each wrdRef In docRef.Words
If Asc(Left(wrdRef, 1)) > 32 Then
With Selection.Find
.Wrap = wdFindContinue
.Text = wrdRef
.Execute Replace:=wdReplaceAll
End With
End If
Next wrdRef
然而,当我将MatchWholeWord语句移动到第二个&#34;用&#34;阻止它起作用。
With Selection.Find
.ClearFormatting
.Forward = True
.Format = True
.MatchCase = True <------------
.MatchWildcards = False
.Replacement.ClearFormatting
.Replacement.Text = "^&"
.Replacement.Highlight = True
End With
For Each wrdRef In docRef.Words
If Asc(Left(wrdRef, 1)) > 32 Then
With Selection.Find
.MatchWholeWord = True <=========
.Wrap = wdFindContinue
.Text = wrdRef
.Execute Replace:=wdReplaceAll
End With
End If
Next wrdRef
现在,这可能没问题,但标志设置语句MatchCase = True
仍然设置。
问题:为什么Selection.Find.MatchWholeWord和Selection.Find.MatchCase与&#34; With&#34;一起表现不同。声明?
(参考:我复制了以下代码: http://word.tips.net/T000502_Highlight_Words_from_a_Word_List.html
注意,我必须对此代码进行的其他更改是添加行.Replacement.Highlight = True