2013-08-19 2 views
0

문서를 검색하고 "for"및 "for"와 같은 다른 공백을 강조 표시하기 위해 수정 된 코드를 사용하여 매크로를 작성하려고합니다. 이 사이트는, 나는이를 입수했습니다 :Microsoft Word 용 VBA 매크로의 텍스트 강조 표시

Sub findfunction() 
If (findHL(ActiveDocument.Content, "[ for ]")) = True Then MsgBox "Highlight Comma's and Coordinating Conjunctions Done", vbInformation + vbOKOnly, "Highlight Result" 
End Sub 

Function findHL(r As Range, s As String) As Boolean 
Options.DefaultHighlightColorIndex = wdYellow 
r.Find.Replacement.Highlight = True 
r.Find.Execute MatchWholeWord:=True, FindText:=s, MatchWildcards:=True, Wrap:=wdFindContinue, Format:=True, replacewith:="", Replace:=wdReplaceAll 
findHL = True 
End Function 

문제는 그냥 문자 F, O, 및 R의 모든 발생을 강조한다는 것이다. "for"시퀀스가 발견되었을 때만 강조 표시하고 개별 문자는 강조하지 않기를 원합니다. 나는 이것에 초보적이며 어디에서 가야할지 모르겠다. 그래서 어떤 도움을 주시면 감사하겠습니다. 감사 : D

+0

[여기에 와일드 카드 규칙이 있는지 확인] (http://www.gmayor.com/replace_using_wildcards.htm) –

답변

0

와일드 카드는 필요하지 않습니다. 검색 문자열은 "for"이고 MatchWildcards : = False 여야합니다.

Sub findfunction() 
    If (findHL(ActiveDocument.Content, " for ")) = True Then 
     MsgBox "Highlight Comma's and Coordinating Conjunctions Done", vbInformation + vbOKOnly, "Highlight Result" 
    End If 
End Sub 

Function findHL(r As Range, s As String) As Boolean 
    Options.DefaultHighlightColorIndex = wdYellow 
    r.Find.replacement.Highlight = True 
    r.Find.Execute MatchWholeWord:=True, FindText:=s, MatchWildcards:=False, Wrap:=wdFindContinue, Format:=True, replacewith:="", Replace:=wdReplaceAll 
    findHL = True 
End Function 
관련 문제