Note that there are some explanatory texts on larger screens.

plurals
  1. POVBA Open Workbook from Macro fails "(path & filename) could not be found. Check the spelling..."
    text
    copied!<p>I have the following code, which should simply open a workbook from a master workbook to allow me to paste some information which I will later retrieve from a database. I receive the error in the title <strong>every time</strong> I try to open a workbook. I have used similar code before with no problem at all. The files are kept on a server away from my desktop, but the path has been correct each time. I've checked over and over again. What could be the culprit?</p> <pre><code>Sub copyDealerDataToWorkbook(ByVal targetID As Integer) Dim mainWB As Workbook Dim directory As String Dim fn As String Dim aFile As Excel.Application Set aFile = CreateObject("Excel.Application") Set mainWB = ActiveWorkbook directory = ActiveWorkbook.Path 'append a "\" If InStrRev(directory, "\") &lt; Len(directory) Then directory = directory &amp; "\" End If fn = targetID &amp; ".xls" aFile.Application.Visible = True aFile.Workbooks.Open directory &amp; fn 'ERROR ON THIS LINE aFile.Parent.Windows(1).Visible = True End Sub </code></pre> <p>I have also tried the following code...</p> <pre><code>Sub copyDealerDataToWorkbook(ByVal targetID As Integer) Dim foreignWB As Workbook Dim mainWB As Workbook Dim directory As String Dim fn As String Set mainWB = ActiveWorkbook directory = ActiveWorkbook.Path 'append a "\" If InStrRev(directory, "\") &lt; Len(directory) Then directory = directory &amp; "\" End If fn = targetID &amp; ".xls" Set foreignWB = Workbooks.Open(fileName:=directory &amp; fn) 'ERROR ON THIS LINE End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload