|
- Sub test()
- Dim p$, f$, sql$
- Set cnn = CreateObject("ADODB.connection")
- p = ThisWorkbook.Path
- If Right(p, 1) <> "" Then p = p & ""
-
- If Application.Version = "11.0" Then
- f = "B表.xls"
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & p & f
- sql = "select a.*,b.单价,b.款式 from [Excel 8.0;Database=" & ThisWorkbook.FullName & "].[A表$a1:e65536] a left join [B表$] b on a.订单编号=b.订单编号"
- Else
- f = "B表.xlsx"
- cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & p & f
- sql = "select a.*,b.单价,b.款式 from [Excel 12.0;Database=" & ThisWorkbook.FullName & "].[A表$a1:e65536] a left join [B表$] b on a.订单编号=b.订单编号"
- End If
-
- With Worksheets(1)
- .Cells.ClearContents
- .[a2].CopyFromRecordset cnn.Execute(sql)
- End With
- End Sub
复制代码 |
|