2017-03-06 1 views
0

를 교체하고 다음과 같은 텍스트 강조한다 :찾기 및 선택 내를 교체하는 것이 테이블 내에 있지 않은 모든 단락을 통해 내가 반복하기 위해 노력하고있어 전체 문서

'Iterate All Paragraphs 
Dim p 
objWord.Options.DefaultHighlightColorIndex = finalColor 
For Each p In objDoc.Paragraphs 
    p.Range.Select 
    If Not objWord.Selection.Information(wdWithInTable) Then 
     With objWord.Selection.Range.Find 
      .ClearFormatting 
      .Highlight = False 
      .Forward = True 
      .Wrap = wdFindStop 
      .Replacement.ClearFormatting 
      .Replacement.Highlight = True 
      .Execute , , , , , , True, wdFindStop, , , wdReplaceAll 
     End With 
    End If 
Next 

조건 objWord.Selection.Information(wdWithInTable) 작품 잘을, 그러나 테이블 내에서도 문서 전체에서 강조 표시되지 않은 텍스트는 찾기/실행으로 대체됩니다.

왜 그런가?

답변

1

필자는 Find 개체를 사용해야한다고 생각하지 않지만, 주장하는 경우 아마도 Selection.Range를 변수에 저장 한 다음 그 .Find 속성을 사용해야합니다.

나는 이런 식으로 뭔가를 할 것이다 :

Sub HighlightNonTableParagraphs() 
    Dim oDocument As Document 
    Dim oParagraph As Paragraph 
    Dim oRange As range 

    Set oDocument = ActiveDocument 

    For Each oParagraph In oDocument.Paragraphs 
     With oParagraph.range 
      If Not .Information(wdWithInTable) Then 
       .HighlightColorIndex = wdBlue 
      End If 
     End With 
    Next 
End Sub