Excel VBA 执行操作SQL

2025-02-27 22:31:46
推荐回答(1个)
回答1:

类似这样
'建立连接
Set cnn = New ADODB.Connection
With cnn
.Provider ="Microsoft.ACE.OLEDB.12.0;Extended Properties=excel 12.0"
.Open "你的工作簿路径" &"\你的工作簿名称.xls"
End With
sqls = "select * from [sheet1$]" ' SQL语句
Set rst = cnn.Execute(sqls)
Sheets("sheet3").Range("A1").CopyFromRecordsetrst