title: How can I open each word document in my file and extract data to put into a cell in Excel VBA
body: <p>At work I have to go into over 400 files individually and grab the subject of the word document and the date it was written (this is found within the report) and put that into an excel list. I've found code to search through a word document and get this data which is working but I've been playing around with it and I can't get it to loop through all files in a folder. Right now I can only do one file at a time which isn't ay faster than doing it by hand.</p>
  <p>The code gets the subject and puts it in a cell.</p>
  <p>Ideally the code would display the file that it took the data from in one cell and in the cell beside it, it would display the subject.</p>
  <p>A video I watched said to loop through I need to use a dir function but I can't get that to work the way I'm doing it.</p>
  <p>This is the code that I have that takes one file at a time.</p>
  <pre><code>Sub ExtractText()
  Dim cDoc As Word.Document
  Dim cRng As Word.Range
  Dim i As Long
  i = 2
  
  Dim wordapp As Object
  Set wordapp = CreateObject(&quot;word.Application&quot;)
  wordapp.Documents.Open &quot;c:\code practice\file1&quot;
  wordapp.Visible = True
  
  Set cDoc = ActiveDocument
  Set cRng = cDoc.Content
  
  With cRng.Find
      .Forward = True
      .Text = &quot;SUBJECT:&quot;
      .Wrap = wdFindStop
      .Execute
      Do While .Found
          'Collapses a range or selection to the starting or ending position
          cRng.Collapse Word.WdCollapseDirection.wdCollapseEnd
          cRng.MoveEndUntil Cset:=&quot;INSPEC&quot;
          Cells(i, 1) = cRng
          cRng.Collapse Word.WdCollapseDirection.wdCollapseEnd
          .Execute
          i = i + 1
      Loop
  End With
  wordapp.Quit
  Set wordapp = Nothing
  
  End Sub
  </code></pre>