title: VBA "Check if folder exists" works only when there is a file in the folder
body: <p>I got the original code from www.rondebruin.nl</p>
  
  <p>It is designed to test whether or not a folder already exists in the directory. I modified it to fit my needs and it seemed to work well. </p>
  
  <p>Today, i discovered that it only works properly if the folder being tested for is NOT empty. If it is empty, then it returns false (i.e. the folder does not exist).</p>
  
  <p>I can't figure out why this is.  </p>
  
  <pre><code>FolderPath = sPfad
  If Right(FolderPath, 1) &lt;&gt; "\" Then
      FolderPath = FolderPath &amp; "\"
  End If
  
  TestStr = ""
  On Error Resume Next
  TestStr = Dir(FolderPath)
  On Error GoTo 0
  If TestStr = "" Then
      Test_Folder_Exist_With_Dir = False
      Exit Function
  Else
      Test_Folder_Exist_With_Dir = True
      Exit Function
  End If
  </code></pre>
  
  <p>I suspect the answer lies in the <code>TestStr = Dir(FolderPath)</code> but haven't been able to get to the bottom of it. The MSDN <a href="https://msdn.microsoft.com/en-us/library/dk008ty4%28v=vs.90%29.aspx" rel="nofollow">article</a> basically explains that <code>Dir()</code> always returns something. However the examples give are all such that there is a file present to return.</p>
  
  <p>I basically need to get it so that it recognizes the folder regardless of whether there is something in it or not.</p>
  
  <p>Any help appreciated!</p>