我尝试连接到一个 excel 数据库(我知道它不是完美的数据库,但我不能使用访问,但我必须使用 excel 所以......)一切正常,直到出现:objRecordset.Open
我得到一个错误,我承认我不知道如何解决它
这是代码
Sub macromacro()
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
'***** Creation de la connection *****
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & ThisWorkbook.Path & "\StatsLyon.xlsm;" _
& "Extended Properties=""Excel 8.0;HDR=Yes;"";"
'***** Requête SQL *****
objRecordset.Open
Query = "Select SUM(NbCompteurElec) AS NombreTotal FROM [Feuil1$] ," _
& "objConnection, adOpenStatic, adLockOptimistic, adCmdText"
Feuil5.Cells(1, 3).Value = "NombreTotal"
Feuil5.Cells(1, 4).Value = objRecordset.Fields(NombreTotal).Value
objConnection.Close
Set objConnection = Nothing
End Sub