title: VBA looping through files that meet two criteria
body: <p>Below is working code that is looping through files in a folder based on a user's search criteria. The folder will grow throughout the year to over 1000 files, so rather than looping through all of them every time the macro runs, I would like to add a second criteria that compares the time stamps on the files to a time stamp saved on the file as the last time it was run. <code>LastUpdateDate</code> is set up as variable in date format at the top of the module, and the old timestamp is saved to it at the beginning of the code.</p>
  
  <p>I tried this but it left me with a run time error. Is this doable using <code>Do While</code>, or is there another format I need to be looking at?  I also tried nesting the date comparison as an <code>if</code> statement under the <code>Do While</code>, but came up with other errors.</p>
  
  <pre><code>Do While FileName &lt;&gt; "" and FileDateTime(FileName) &gt; LastUpdateDate
  </code></pre>
  
  <p>Working code from this section:</p>
  
  <pre><code>FileName = Dir(FolderName &amp; "*" &amp; MyCriterion &amp; "*" &amp; ".xl??")   
  
  'Loop through all matching files
  Do While FileName &lt;&gt; ""
      'Open the next matching workbook
      Workbooks.Open (FolderName &amp; FileName)
      Sheets("Report Data").Select
      'Call GrabTheData
      GrabTheData
  
      'Close the workbook
      Workbooks(FileName).Close savechanges:=False
  
      'Get the name of the next match in folder
  
      FileName = Dir
  Loop
  
  End Sub
  </code></pre>