"Cannot run in Excel connection
Set cn = CreateObject("ADODB.Connection")
cn.Open "Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\testing.xls; ReadOnly=False;"
''It shows error message at this line
''Sheet1' is sheet name, 'COLUMN1', 'COLUMN2' are column names
Set rs = cn.Execute ("select * from [Sheet1$] where COLUMN1='2'")
Do while not rs.eof
msgbox rs.Fields("COLUMN2").Value
Loop
Set rs= nothing
Set con= nothing
本文介绍了一段使用VBA连接Excel文件并读取特定工作表数据时出现的错误及可能的原因。通过创建ADODB.Connection对象并尝试执行SQL查询来定位问题所在。
31万+

被折叠的 条评论
为什么被折叠?



