title: Excel VBA: Combine multiple workbooks into one workbook
body: <p>I have used the following script to copy multiple workbooks (sheets 1 only) into one master workbook. But, as multiple files are saved in the source folder each day, I now have hundreds of files in my source folder and would like to refine the folders that I copy to the master file.</p>
  
  <p>I there a way to restrict the folders by using a date that appears in the file names. File path is ALWAYS the same format ...</p>
  
  <p>5 alpha characters __ the date the file was saved (dateformat: ddmmyy) __ Julian Date</p>
  
  <p>e.g.</p>
  
  <p>NOCSR__060715__162959</p>
  
  <p>SBITT__060715__153902</p>
  
  <p>LVECI__030715__091316</p>
  
  <p>Can I use the date in the file path and allow the user the input 'from' and 'to' dates? The master workbook would then only pull data from files that were saved within the date range.</p>
  
  <pre><code>Sub MergeFilesWithoutSpaces()
      Dim path As String, ThisWB As String, lngFilecounter As Long
      Dim wbDest As Workbook, shtDest As Worksheet, ws As Worksheet
      Dim Filename As String, Wkb As Workbook
      Dim CopyRng As Range, Dest As Range
      Dim RowofCopySheet As Integer
  ThisWB = ActiveWorkbook.Name
  
  path = "K:\UKSW CS Bom Expections\CS_BOM_Corrections\Archive"
  
  RowofCopySheet = 2
  
  Application.EnableEvents = False
  Application.ScreenUpdating = False
  
  Set shtDest = ActiveWorkbook.Sheets(1)
  Filename = Dir(path &amp; "\*.xls", vbNormal)
  If Len(Filename) = 0 Then Exit Sub
  Do Until Filename = vbNullString
      If Not Filename = ThisWB Then
          Set Wkb = Workbooks.Open(Filename:=path &amp; "\" &amp; Filename)
          Set CopyRng = Wkb.Sheets(1).Range(Cells(RowofCopySheet, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, Cells(1, Columns.Count).End(xlToLeft).Column))
          Set Dest = shtDest.Range("A" &amp; shtDest.Cells(Rows.Count, 1).End(xlUp).Row + 1)
          CopyRng.Copy
          Dest.PasteSpecial xlPasteFormats
          Dest.PasteSpecial xlPasteValuesAndNumberFormats
          Application.CutCopyMode = False 'Clear Clipboard
          Wkb.Close False
      End If
  
      Filename = Dir()
  Loop
  </code></pre>
  
  <p>Thanks, SMORF</p>