|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
qdsky 发表于 2012-2-3 12:41
老师看这样的结果能不能做到? - Dim arr_File()
- Dim ary(), m As Long, mm As Long
- Sub Macro1()
- Dim arr, brr(1 To 60000, 1 To 6), n&, i As Long, sh As Worksheet
- Dim fp$, obmapp As Object, d As Object
- Set d = CreateObject("scripting.dictionary")
- arr = Range("f2:f" & Range("f65536").End(xlUp).Row)
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = ""
- Next
- ' ReDim brr(1 To i - 1, 1 To 4)
- Set obmapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件目录:", 0, 0)
- If Not obmapp Is Nothing Then
- fp = obmapp.Self.Path & ""
- Else
- Exit Sub
- End If
- m = 2
- ReDim ary(1 To m)
- ary(1) = fp
- i = 1
- Do While ary(i) <> ""
- dirdir (ary(i))
- i = i + 1
- Loop
- For Each cel In ary
- If cel <> "" Then Call dirf(cel)
- Next
- Application.ScreenUpdating = False
- For l = 1 To mm
- With GetObject(arr_File(l))
- For Each sh In .Sheets
- If sh.[f65536].End(xlUp).Row > 1 Then 'F列有数据
- arr = sh.UsedRange
- For i = 2 To UBound(arr)
- ' n = d(arr(i, 6))
- If d.Exists(arr(i, 6)) Then
- n = n + 1
- brr(n, 1) = arr(i, 1)
- brr(n, 2) = "N"
- brr(n, 4) = arr(i, 4)
- brr(n, 6) = arr(i, 6)
- End If
- Next
- End If
- Next
- .Close False
- End With
- Next
- Range("a2:d65536").ClearContents
- [a2].Resize(UBound(brr), 6) = brr
- m = 0
- mm = 0
- Erase ary
- Application.ScreenUpdating = True
- End Sub
- Sub dirdir(MyPath)
- Dim MyName
- MyName = Dir(MyPath, vbDirectory)
- Do While MyName <> ""
- If MyName <> "." And MyName <> ".." Then
- If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
- m = m + 1
- ReDim Preserve ary(1 To m)
- ary(m - 1) = MyPath & MyName & ""
- End If
- End If
- MyName = Dir
- Loop
- End Sub
- Sub dirf(My_Path)
- MyFileName = Dir(My_Path & "*.xls")
- Do While MyFileName <> ""
- If InStr(MyFileName, "mm") Then
- mm = mm + 1
- ReDim Preserve arr_File(1 To mm)
- arr_File(mm) = My_Path & MyFileName
- End If
- MyFileName = Dir
- Loop
- End Sub
复制代码 |
|