Sub RunCode()
Dim ConnStr As String
ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes';Data Source =" & ThisWorkbook.FullName '//需OFFICE 2007及以上版本
Set conn = CreateObject("adodb.connection")
conn.Open ConnStr
Sql = "select * from [Sheet1$] AS A"
Sql = Sql + " Left Join [Sheet2$] AS B ON A.条码=B.条码"
Set rs = conn.Execute(Sql)
Sheets("Sheet3").Select
Sheets("Sheet3").Cells.Clear
Range("A1").CopyFromRecordset rs '将结果可以放到单元格内
End Sub
EXCEL-VBA:通过SQL查询数据Sheet中的数据
最新推荐文章于 2024-06-14 20:43:06 发布