title: VBA get all occurences of a style in a Word document from Excel
body: <p>For my work I have to find all the instances of a style in 40 word documents (.doc). Once I get the text, I want to write it in a cell in my excel sheet (.xls).</p>
  
  <p>With the code I wrote I can get the first instance of that style but I cannot get the next one, it goes into an infinite loop and I don't now why (there are about 10 occurrences on each file).</p>
  
  <p>Could you tell me where I am wrong?</p>
  
  <p>I want to go from that:
  <a href="http://i.stack.imgur.com/Ysgfe.jpg" rel="nofollow">Before running the macro</a>
  to that:
  <a href="http://i.stack.imgur.com/xs1nz.jpg" rel="nofollow">After running the macro</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>'==================================================================
  ' Declarations
  '==================================================================
  
  Dim ObjWord As Object ' Word application object
  
  '==================================================================
  ' Macro
  '==================================================================
  
  Public Sub Macro()
  
  Dim row As Integer
  row = 9 'first available row
  
  Set ObjWord = CreateObject("word.application")
  
  Worksheets("Sheet 2").Activate
  
  While (Cells(row, 2).Value &lt;&gt; "End of file list")
  
      Set file = ObjWord.documents.Open(ThisWorkbook.path &amp; ".\" &amp; Cells(row, 1).Hyperlinks(1).Address)
  
  
      Set currentRange = file.Range
  
      currentRange.Find.ClearFormatting
      currentRange.Find.Forward = True
      currentRange.Find.Text = ""
      currentRange.Find.Style = "MyStyle"
      bFind = currentRange.Find.Execute
  
      Do While bFind 'here is the endless loop
           row = row + 1
           StyleValue= currentRange.Text 'I get stuck with the first value :-(
           Rows(row).EntireRow.Insert
           Cells(row, 2).Value = StyleValue
           bFind = currentRange.Find.Execute
      Loop
  
      file.Close
  
      row = row + 1 ' next File
  Wend
  
  ObjWord.Quit
  End Sub
  </code></pre>