title: VBA dir() returns empty string
body: <p>I'm trying to get this vba working. It reads the correct filestructure and it does find the first .xlsx and it import the needed data to the control.xlsm.</p>
  
  <p>I notice that after it gets to fileName = dir() the fileName becomes empty. I read that it does this because it cannot find files that match the criteria, but what am i doing wrong?</p>
  
  <p>Here is the code</p>
  
  <pre><code>     Sub test_werk_final()
     Application.ScreenUpdating = False
     Application.CutCopyMode = False
     Application.DisplayAlerts = False
  
    Dim directory, fileName As String, sheet As Worksheet
  
   directory = ThisWorkbook.Path &amp; "\"
  
  fileName = Dir(directory &amp; "*.xlsx")
  controlFile = Dir(directory &amp; "control.xlsm")
    lijn = 2
    MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
    Do Until fileName = ""
      MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
  
         Workbooks.Open fileName:=(directory &amp; fileName)
           MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
  naam = Sheets("Sheet2").Range("A1").Value
  
  leeftijd = Sheets("Sheet2").Range("A2").Value
  
  Workbooks(controlFile).Worksheets("control").Cells(lijn, 1) = naam
  Workbooks(controlFile).Worksheets("control").Cells(lijn, 2) = leeftijd
  For Each sheet In Workbooks(fileName).Worksheets
  naam = Workbooks(fileName).Worksheets.Range("A1").Value
  leeftijd = Workbooks(fileName).Worksheets.Range("A2").Value
  
  Workbooks(controlFile).Worksheets("control").Cells(lijn, 1) = naam
  Workbooks(controlFile).Worksheets("control").Cells(lijn, 2) = leeftijd
  Next sheet
  Workbooks(fileName).Close
    MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
  lijn = lijn + 1
           MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
  
  
         fileName = Dir() ' volgende
           MsgBox "1" &amp; directory &amp; "2" &amp; fileName &amp; "3" &amp; controlFile
   Loop
      Application.ScreenUpdating = True
  </code></pre>
  
  <p>I'm not an expert coding guru, but i do posses basic programming skills. </p>
  
  <p>P.S: i already looked for the questone on differnt fora en didn't find anything that could help me. Maybe i used the wrong search string. </p>
  
  <p>Thanks in advance</p>