|
本帖最后由 jave000 于 2022-7-18 16:00 编辑
liulang0808 发表于 2022-7-18 07:09
这个需要提供下报错的测试文档
Sub button9_click()
Application.ScreenUpdating = False
Set Fso = CreateObject("scripting.filesystemobject")
ActiveSheet.Range.ClearContents
Set f1 = Fso.getfolder("\\jsvr5.net\")
a = 1
For Each fd1 In f1.subfolders
Cells(a, 1) = fd1
a = a + 1
Next fd1
Set f2 = Fso.getfolder("\\jsvr5.net\AB\D4")
b = a
For Each fd2 In f2.subfolders
Cells(b, 1) = fd2
b = b + 1
Next fd2
Set f3 = Fso.getfolder("\\jsvr5.net\C1\")
c = b
For Each fd3 In f3.subfolders
Cells(c, 1) = fd3
c = c + 1
Next fd3
Dim o
For o = 1 To 2000
ActiveSheet.Hyperlinks.Add Anchor:=Cells(o, 1), Address:=Cells(o, 1).Value
Next
Application.ScreenUpdating = True
End Sub
我后来用可以获取全部子文件夹的代码修改成如下代码,解决了关键词获取的问题,但是发现新的问题是代码只支持下一层子文件夹,不再支持全部子文件夹了,于是我自己又加了一层For Each fe In fd.subfolders。
这个距离使用还有两个障碍,一个是因为只支持一层子文件夹,Getfd需要输入多个地址了,请问可以怎么写?还有一个是关键词"out"不够,我有两种关键词,试了or不行。
Sub button9_click()
Application.ScreenUpdating = False
ActiveSheet.UsedRange.ClearContents
Cells(1, 1) = "Project Path"
Getfd ("C:\Users\asaman\Desktop\path\")
Dim o
For o = 1 To 5000
ActiveSheet.Hyperlinks.Add Anchor:=Cells(o, 1), Address:=Cells(o, 1).Value
Next
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth)
Set Fso = CreateObject("scripting.filesystemobject")
Set ff = Fso.getfolder(pth)
Cells(Rows.Count, 1).End(3).Offset(1) = pth
For Each fd In ff.subfolders
For Each fe In fd.subfolders
If LCase(fe.Name) Like "out" & "*" Then
Getfd (fe)
End If
Next fe
Next fd
End Sub |
|