|
用于完成你的要求的完整代码如下:
- Option Explicit
- Dim arr(), k&
- Sub byWanao()
- Dim i&, j&, wb As Workbook, sht As Worksheet, jsNum&, rowNum&
- Application.ScreenUpdating = False
- Call TestFindAllFiles
- rowNum = 19
- Sheet1.Range("A20:O65536").ClearContents
- For k = 1 To UBound(arr)
- Set wb = GetObject(arr(k))
- For Each sht In wb.Sheets
- jsNum = 0
- If sht.Range("A15") <> "" Or sht.Range("A15").End(xlUp).Row > 4 Then
- For j = 1 To 9 Step 6
- For i = 4 To 15
- If sht.Cells(i, j) = "" Then Exit For
- jsNum = jsNum + 1
- rowNum = rowNum + 1
- With Sheet1
- .Cells(rowNum, 1) = jsNum
- .Cells(rowNum, 2) = sht.Cells(i, j)
- If j = 1 Then
- .Cells(rowNum, "k") = sht.Cells(i, j + 2)
- .Cells(rowNum, "l") = sht.Cells(i, j + 3)
- Else
- .Cells(rowNum, "k") = sht.Cells(i, j + 1)
- .Cells(rowNum, "l") = sht.Cells(i, j + 2)
- End If
- .Cells(rowNum, "m") = "=L" & rowNum & "-K" & rowNum
- .Cells(rowNum, "n") = "=M" & rowNum & "/K" & rowNum
- .Hyperlinks.Add Anchor:=.Cells(rowNum, "o"), Address:=arr(k), _
- TextToDisplay:=wb.Name & "" & sht.Name
- End With
- Next
- Next
- End If
- Next
- Stop
- wb.Close savechanges:=False
- Set wb = Nothing
- Next
- Application.ScreenUpdating = True
- End Sub
- Sub TestFindAllFiles()
- Erase arr
- k = 0
- FindAllFiles ThisWorkbook.Path
- End Sub
-
- Sub FindAllFiles(fsPath$)
- Dim fs, f, fd, m$, n$
- Set fs = CreateObject("Scripting.FileSystemObject").getFolder(fsPath)
- For Each f In fs.Files
- If f.Name Like "*.xls*" Then
- If Left(f.Name, 2) <> "~$" And f.Name <> ThisWorkbook.Name Then
- k = k + 1
- ReDim Preserve arr(1 To k)
- arr(k) = fsPath & "" & f.Name
- End If
- End If
- Next
- For Each fd In fs.subfolders
- FindAllFiles fsPath & "" & fd.Name
- Next
- End Sub
复制代码 如果有任何疑问,可看教学视频:
https://www.bilibili.com/video/BV1qs4y1M7od/
如果解决了你的问题,请给朵小红花!
|
评分
-
1
查看全部评分
-
|