title: VBA Open multiple files in selection to copy into mastersheet
body: <p>I created a macro in VBA (excel) to open a specific range of a daily file which all have a similar start of the name (9489) followed by a file specific date (DD-MM-YY). The selection is then copied into the masterfile (Masterfile.xlsm), this sub is run for all the files from the directory.</p>
  
  <p>Since today however I keep getting an error named "Run-time error 1004: 9489 150116 Daily Dashboard.xlsx could not be found. Check the spelling of the file name, and verify that the file location is correct."</p>
  
  <p>Why do I get this error? Most importantly, can anybody help me solve this error? I did not change the spelling of the file or the files location!</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>Sub LoopThroughDirectory() 
  Dim Myfile As String 
  Dim erow 
  Myfile = Dir("F:\WGD\Dep 408101-Se-DCIFINK-009786\Consolidatie &amp; Regulatory Reporting\Regulatory Reporting\Daily dashboard of Ratios\Test Daily Dashboard\")
  Application.DisplayAlerts = False
  
  Do While Len(Myfile) &gt; 0 
  If Myfile = "Masterfile.xlsm" Then
  
  Exit Sub
  
  End If
  
  Workbooks.Open (Myfile) 
  Worksheets("Liquidity Reporting").Range("A2:E19").Copy
  
  Windows("Masterfile.xlsm").Activate 
  erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row 
  ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 5))
  
  Workbooks(Myfile).Application.CutCopyMode = False 
  Workbooks(Myfile).Close SaveChanges:=False
  
  Myfile = Dir
  
  Loop
  
  End Sub
  </code></pre>