title: Compare File Date Modified in VBA
body: <p>So I am writing a code in VBA that opens up all files in a document and copies and pastes the information from each document. The code is set up to open up every document, but itself. My dilemma is that I want the code to open ever document that has been modified after the last day the main file has been modified. Basically I want to compare two dates with one date staying the same and the other changing after every loop (new document every loop). My code is below and any help or suggestion would be much appreciated. Thanks! </p>
  
  <pre><code>Sub LoopThroughDirectory()
  Dim MyFile As String
  Dim erow
  Dim Filepath As String
  Dim DateMaster As Date
  Dim DateReflections As Date
  
  Filepath = "Path of folder where all the documents are"
  MyFile = Dir(Filepath)
  DateReflections = FileDateTime(Filepath)
  DateMaster = FileDateTime("Filepath of master document I'm comparing to")
  
  Do While Len(MyFile) &gt; 0
   If MyFile = "zmasterfile.xlsm" Then
  Exit Sub
   If DateReflections &lt; DateMaster Then
  Exit Sub
  End If
  
  Workbooks.Open (Filepath &amp; MyFile)
  Range("B4:N4").Copy
  ActiveWorkbook.Close
  
  erow = Sheet1.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
  ActiveSheet.Paste Destination:=Worksheets("Reflections").Range(Cells(erow, 2), Cells(erow, 14))
  
  MyFile = Dir
  
  Loop
  End Sub
  </code></pre>