|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub lkyy()
Dim MyPath As String, MyFile, Sql, SqlA
Application.ScreenUpdating = False
Range("a1").CurrentRegion.ClearContents
On Error Resume Next
MyPath = ThisWorkbook.Path & "\"
MyFile = Dir(MyPath & "*.xlsx")
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties='excel 12.0;hdr=yes';data source=" & MyPath & MyFile
Do While MyFile <> ""
biao = Replace(MyFile, ".xlsx", "")
If biao = "A" Then
SqlA = "select 商品编号,'" & biao & "' as 表 from [" & MyPath & MyFile & "].[" & biao & "$]"
Else
Sql = Sql & " union all select 商品编码,'" & biao & "' as 表 from [" & MyPath & MyFile & "].[" & biao & "$]"
End If
MyFile = Dir()
Loop
Sql = Right(Sql, Len(Sql) - 11)
ss = "select a.商品编号 from (" & SqlA & ")a left join (" & Sql & ")b on a.商品编号=b.商品编码 where b.商品编码 is null"
Range("i5:i20").ClearContents
Range("i5").CopyFromRecordset cnn.Execute(ss)
cnn.Close
Set cnn = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|