Microsoft KB Archive/316809

= BUG: No ADO Connection Error When Excel Workbook Is Not Found =

Article ID: 316809

Article Last Modified on 1/31/2002

-

APPLIES TO


 * Microsoft OLE DB Provider for Jet 4.0

-



This article was previously published under Q316809



SYMPTOMS
When you attempt to make an ADO connection to a Microsoft Excel workbook, and the path and file name supplied in the ADO connection string are invalid, or the Excel file is missing, ADO does not generate an error message as expected when the connection fails.

You receive the following error message only when you attempt to open a recordset from the Excel workbook, and the error message does not clearly reveal the underlying cause of the problem:

Runtime error '-2147217865 (80040e37)': The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.

This behavior occurs with both the Microsoft Jet OLE DB Provider 4.0 and the Microsoft Excel ODBC Driver.



RESOLUTION
To work around this issue, carefully verify not only the name and spelling of the source table (or tables) named in your query, but the name and spelling of the Excel path and file name supplied in your ADO connection string.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Problem
 Create a new Visual Basic Standard EXE project, and then set a reference to Microsoft ActiveX Data Objects (ADO).  Place the following code in the Form_Load event of the default Form1.

Note that it references a nonexistent Excel workbook. Private Sub Form_Load Dim cn As ADODB.Connection Dim strCn As String Dim rs As ADODB.Recordset Set cn = New ADODB.Connection strCn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _ &quot;Data Source=&quot; & App.Path & &quot;\missing.xls;&quot; & _ &quot;Extended Properties=Excel 8.0&quot; '   strCn = &quot;Driver={Microsoft Excel Driver (*.xls)};&quot; & _ '       &quot;DBQ=&quot; & App.Path & &quot;\missing.xls&quot; cn.Open strCn Set rs = cn.Execute(&quot;SELECT * FROM [Sheet1$]&quot;) End Sub  Run the project by using the Jet 4.0 Provider.

You receive the error message. Switch the active connection string, and then run the project again by using the Excel ODBC Driver.

You receive the error message.

