软件: Excel
版本: 2016
初次尝试ADO SQL,失败收场....
目的是想从 Local Excel 抓取数据库的 sheet1
出现错误为物件定义错误 (请看贴图说明)
请问这该怎么解呢?
'************贴图说明**************
https: //ppt.cc/fF8LJx
***********************************
'**********Code 如下***************
Sub MySQL_1st()
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Acer\Desktop\excel\SQL\raw\raw_data.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordset.Open "Select * FROM [sheet1$]", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
Wscript.Echo objRecordset.Fields.Item("ID")
objRecordset.MoveNext
Loop
End Sub