2016-07-20 13 views
1

VBAマクロを使用してMicrosoft Wordでスタイル検索を実行しています。 私の目標は、文書内のすべてのスタイルに対して特定のアクションを1回実行することです。Microsoft Word VBAマクロ - 1段落検索置換スタイル

マクロは少なくとも2つの段落を持つドキュメントで正しく動作しますが、マクロではその段落が1つの段落だけのドキュメントで正しくスタイルを警告しません。新しい段落記号を入力すると、文書に新しいテキストやスタイルを追加しなくても、スタイルが見つかるということは奇妙に思えます。余分な空白の段落記号だけです。誰も私のマクロで何が間違っているのか、私はこれをどのように修正できるのか分かっていますか?見ていただきありがとうございます。

Sub AlertAllStylesInDoc() 
    Dim Ind As Integer 
    Dim numberOfDocumentStyles As Integer 
    Dim styl As String 
    Dim StyleFound As Boolean 

    numberOfDocumentStyles = ActiveDocument.styles.count 

    For Ind = 1 To numberOfDocumentStyles 
     styl = ActiveDocument.styles(Ind).NameLocal 
     With ActiveDocument.Content.Find 
      .ClearFormatting 
      .text = "" 
      .Forward = True 
      .Format = True 
      .Style = styl 
      Do 
       StyleFound = .Execute 
       If StyleFound = True Then 
        ' actual code does more than alert, but keeping it simple here' 
        MsgBox styl 
        GoTo NextStyle 
       Else 
        Exit Do 
       End If 
      Loop 
     End With 

    NextStyle: 
     Next 

End Sub 

答えて

1

ActiveDocument.Contentが作業していて、(Wordの2016年にテストした)問題を解決するためにActiveDocument.Range(0,0)表示されて、それを交換していない理由を私は理解していません。

With ActiveDocument.Range(0, 0).Find

+0

ありがとうございます!それは大きな助けです。 – user773328

関連する問題