|
Sub test()
Dim f$
'f = ThisWorkbook.Path & Application.PathSeparator & "1.xlsx" '指定工作簿
With Application.FileDialog(msoFileDialogOpen) '选择工作簿
.InitialFileName = ThisWorkbook.Path
With .Filters
.Clear
.Add "Excel文件(xls*)", "*.xls*"
End With
.AllowMultiSelect = False
If .Show Then f = .SelectedItems(1) Else Exit Sub
End With
Dim Conn As Object, SQL$
Set Conn = CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
SQL = "[" & ActiveSheet.Name & "$F3:F" & Cells(Rows.Count, "F").End(xlUp).Row & "]"
SQL = "SELECT a.商品编号,b.商品名称,b.商品规格,b.生产企业,b.批准文号 FROM " & SQL & " a LEFT JOIN [Excel 12.0;Database=" & f & "].[$A2:H] b ON a.商品编号=b.商品编号"
Range("F4").CopyFromRecordset Conn.Execute(SQL)
Conn.Close: Set Conn = Nothing
MsgBox " ok!", 64
End Sub |
评分
-
2
查看全部评分
-
|