|
Sub QUERY()
Dim AR As Object
Dim K, K1 As Long
Dim FSO, FD, SFD, FL As Object
Dim S As String
Application.DisplayAlerts = False
S = ActiveWorkbook.Path
R1 = ActiveSheet.Range("A1048576").End(xlUp).Row
If R1 > 1 Then
ActiveSheet.Range("A2:D" & R1).Clear
End If
Set FSO = CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set FD = FSO.GETFOLDER(S)
For Each SFD In FD.SUBFOLDERS
For Each FL In SFD.Files
If UCase(FSO.GETEXTENSIONNAME(FL)) = "XLS" Or UCase(FSO.GETEXTENSIONNAME(FL)) = "XLSX" Then
Set WB = GetObject(FL)
For K = 1 To WB.Sheets.Count
R = WB.Sheets(K).Range("A1048576").End(xlUp).Row
If WB.Sheets(K).Cells(1, "D") Like "*" & ActiveSheet.Cells(1, "C") & "*" Then
Set AR = WB.Sheets(K).Range("A2:D" & R)
ActiveSheet.Cells(2, "A").Resize(R - 1, 4) = AR()
WB.Close
With ActiveSheet.Range("A2:D" & Range("A1048576").End(xlUp).Row)
.Borders.LineStyle = xlContinuous
.Cells.HorizontalAlignment = xlCenter
End With
MsgBox "OK"
Application.DisplayAlerts = True
End '假设料号不重复,只在一张表中,若有重复,要一代码即可
End If
Next K
End If
WB.Close
Set WB = Nothing
Next FL
Next SFD
End Sub
|
评分
-
1
查看全部评分
-
|