使用VBA中使用ADO连接excel报错
请请教大神为什么执行下面这段代码时会报错...Subtest()DimadoconAsObject,strsqlAsString,strconAsStringSetado...
请请教大神为什么执行下面这段代码时会报错...
Sub test()
Dim adocon As Object, strsql As String, strcon As String
Set adocon = CreateObject("adodb.connection")
strcon = "provider=microsoft.ace.oledb.12.0;" & _
"data source=" & ThisWorkbook.Path & Application.PathSeparator & _
"数据库.xlsx;extended properties=""excel 12.0;HDR = YES"";"
strsql = "select 数量 from [Sheet1$a1:b4] where 动物 = 乌龟"
adocon.Open strcon
ActiveSheet.Range("b1").CopyFromRecordset adocon.Execute(strsql)
adocon.Close
End Sub 展开
Sub test()
Dim adocon As Object, strsql As String, strcon As String
Set adocon = CreateObject("adodb.connection")
strcon = "provider=microsoft.ace.oledb.12.0;" & _
"data source=" & ThisWorkbook.Path & Application.PathSeparator & _
"数据库.xlsx;extended properties=""excel 12.0;HDR = YES"";"
strsql = "select 数量 from [Sheet1$a1:b4] where 动物 = 乌龟"
adocon.Open strcon
ActiveSheet.Range("b1").CopyFromRecordset adocon.Execute(strsql)
adocon.Close
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询