help out-excel vba
i am getting error msg as 'Run time error '-2147418113(8000ffff)' on executing the following code
Public Sub ch()
Dim Recordset As ADODB.Recordset
Dim ConnectionString As String
ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 8.0;"
Dim SQL As String
'TESTRNG is an excel range name, which defines the table to query, with field names in the first, header row, and records in other rows.
SQL = "SELECT * FROM [Sheet2$];"
Set Recordset = New ADODB.Recordset
On Error GoTo 0
Call Recordset.Open(SQL, ConnectionString, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
Call Range("C10").CopyFromRecordset(Recordset)
Cleanup:
Debug.Print Err.Description
If (Recordset.State = ObjectStateEnum.adStateOpen) Then
Recordset.Close
End If
Set Recordset = Nothing
End Sub
pls suggest.
|