|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
更多文件也可以
Sub limonet()
Dim Cn As Object, StrSQL$, Path$, FileName$
Set Cn = CreateObject("ADODB.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Path = ThisWorkbook.Path & "\"
FileName = Dir(Path & "*.xls")
Do While FileName <> ""
If FileName <> "Limonet.xlsm" Then
StrSQL = StrSQL & " Union All Select 選項號碼 As 選項號碼,Last(料號) As 料號,Last(品名) As 品名 From [Excel 12.0;DataBase=" & Path & FileName & "].[石中$E:K] Group By [選項號碼]"
End If
FileName = Dir
Loop
StrSQL = "Select 料號,品名 From [Sheet1$G:G]a Left Join (" & Mid(StrSQL, 12) & ")b On a.選項號碼=b.選項號碼"
Range("H2").CopyFromRecordset Cn.Execute(StrSQL)
End Sub |
评分
-
1
查看全部评分
-
|