I am trying to read an Excel worksheet into an ADO recordset so that I can read the values from the Excel file. However, I cant seem to get this last part to work.
I have tried everything I know - even searching the internet - but I cant seem to figure out why when I try to execute this line in the code
I always seem to get the following error:VB Code:
oRs.Open sRequest, sCnn, adOpenDynamic, adLockOptimistic
The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure that the object exist and that its name and path name correctly.
I know that Sheet1 exist in the Excels File Path.
Any other ideas why this error is occurring? - Thanks In Advance![]()
VB Code:
Private Sub Form_Load() Dim sPath As String Dim oRs as ADODB.Recordset sPath = App.Path & "\Las Animas Text.xls" Set oRs = GetADOExcelRecordSet(sPath) End Sub Private Function GetADOExcelRecordSet(ByVal Path As String, _ Optional ByVal Headers As Boolean = True) As Recordset Dim sCnn As String Dim sWorksheet As String Dim sRequest As String sWorksheet = "Sheet1" Dim oCnn As ADODB.Connection Set oCnn = New ADODB.Connection Dim oRs As Recordset Set oRs = New ADODB.Recordset sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Path & ";" & _ "Extended Properties=""Excel 8.0;HDR=No" & _ IIf(Headers, "Yes", "No") & """" 'Read a sheet: sRequest = "SELECT * FROM [" & sWorksheet & "$]" oRs.Open sRequest, sCnn, adOpenDynamic, adLockOptimistic Set GetADOExcelConnection = oRs End Function




Reply With Quote