title: VBA error 1004 Sorry, we couldn't find
body: <p>I've receive the above error for the following code:</p>
  
  <pre><code>            Dim location_results As String
              location_results = Worksheets("merging").Range("B1").Text 'absorbing the initial computation results folder
              file_results = Dir$(location_results &amp; "\" &amp; "*" &amp; NBDID &amp; "*" &amp; ".*") 'checks if there is a file with NBDID in the "location results folder
              If (Len(file_results) &gt; 0) Then
                  Worksheets("list").Range("D" &amp; i).Value = file_results                         
              Else
                  MsgBox (NBDID &amp; " result not found")
              End If
  
              'problem todoB:
  lineD:
              Dim shortlocation As String
              shortlocation = ThisWorkbook.Path &amp; "\megaresults\" &amp; file_results
  On Error GoTo lineD
                  'Workbooks(shortlocation).Open
                  Set InputFile = Workbooks.Open(FileName:=shortlocation)
                  'Set InputFile = Workbooks.Open(location_results &amp; file_results)
                  Set OutputFile = Workbooks.Open(location_merger &amp; file_merger)
                  On Error GoTo 0
  </code></pre>
  
  <p>The error is raised on the line:</p>
  
  <pre><code>                Set InputFile = Workbooks.Open(location_results &amp; file_results)
  </code></pre>
  
  <p>and on the line:</p>
  
  <pre><code>                Set InputFile = Workbooks.Open(FileName:=shortlocation)
  </code></pre>
  
  <p>Now googling that error, nearly everyone has an issue that the file they are trying to open is not in the parents-workbook folder, or that they did not preappend their path to the file specification. </p>
  
  <p>I have done that however, and the path is validated, both manually by me checking whether the file is in the folder, as well as with:</p>
  
  <pre><code>            If (Len(file_results) &gt; 0) Then
                  Worksheets("list").Range("D" &amp; i).Value = file_results                         
              Else
                  MsgBox (NBDID &amp; " result not found")
              End If
  </code></pre>
  
  <p>, the file exists, and the total path, including file name and extention is 222 characters long. It also contains spaces.</p>
  
  <p>But I can't find any reason for it to return as an error. On top of that, the on error goto lineD does not function, it still pops up with a message that does not allow continuing of the code.</p>
  
  <p>Could someone point out my mistake to me, or give me a solution that would work?</p>
  
  <p>Kind regards.</p>