|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
新建一个把代码放进去
Sub getworkbooksB()
'指定固定文件夹导入
Dim mydir
Dim Ws As Worksheet
Dim thiswb As Workbook
Const fd = "D:\下载待分类\文件1\文件\原始数据"
Dim i&, j&, m&
Dim arr, brr
Dim temp$, temp1$
Call 禁止
On Error Resume Next
Set thiswb = ThisWorkbook
'fd = "C:\Users\ZY86385\Desktop\all"
'fd = Worksheets("Menu").[s2].Value
ReDim arr(m)
arr(m) = Array("型号", "交期", "数量", "所在工作表")
mydir = fd & "\"
fname = Dir(fd & "\*.xls*")
Do Until fname = ""
Set wkb = Workbooks.Open(Filename:=fd & "\" & fname)
For Each Ws In wkb.Worksheets
brr = Ws.UsedRange
For i = 1 To UBound(brr)
If brr(i, 2) Like "物料*" Then temp = brr(i, 2): temp1 = wkb.Name & "|" & Ws.Name
If brr(i, 2) Like "[A-Z] #*" Then
m = m + 1
ReDim Preserve arr(m)
arr(m) = Array(temp, brr(i, 2), brr(i, 4), temp1)
End If
Next
Next
wkb.Close False
fname = Dir()
Loop
' MsgBox (CStr(fd) & "下Excel文件导入完成!")
Set Ws = Nothing
Set fname = Nothing
Set thiswb = Nothing
Sheets(1).Select
Sheets(1).Rows.Clear
ReDim brr(m, 1 To 4)
For i = 0 To m
For j = 1 To 4
brr(i, j) = arr(i)(j - 1)
Next
Next
For i = m To 1 Step -1
If brr(i, 1) = brr(i - 1, 1) Then brr(i, 1) = ""
Next
[a1].Resize(m, 4) = brr
Erase arr
Erase brr
Call 恢复
End Sub
Sub 禁止()
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual
End Sub
Sub 恢复()
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlAutomatic
End Sub
|
|