求助,EXCEL通过VBA操作SQL数据库

如题所述

Sub QuerySQLSheet()
Dim cnn As Object
Dim SQL$
Set cnn = CreateObject("ADODB.Connection")
mypath = ThisWorkbook.FullName
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;extended properties=excel 12.0;Data Source=" & mypath
SQL = "select * from [AAA$A1:E6] where 姓名='" & [l2] & "'"
'SQL = "update [AAA$] set 年龄='99'where 姓名='张三'"
'cnn.Execute (SQL)
[k5].CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答