0

我正在使用此代码,但我正在尝试更改它以获取文件夹路径列表。代码在目录中查找单元格C和D中输入文本的文件夹名称,但返回结果时没有循环。

Sub GetPath()

    Dim searchFolderName As String
    
    searchFolderName = "D:\"
    
    Dim FileSystem As Object

    Set FileSystem = CreateObject("Scripting.FileSystemObject")

   doFolder FileSystem.GetFolder(searchFolderName)

End Sub

Sub doFolder(folder)
    Dim subFolder
    Dim myLastRow As Long, myRow As Long
    myLastRow = Cells(Rows.Count, "C").End(xlUp).Row
    
    On Error Resume Next
    For myRow = 3 To myLastRow
    If Cells(myRow, "C") = "" Then
            On Error Resume Next
              End If
              FolderName = "P_BNB_" & Cells(myRow, "C") & "_" & Cells(myRow, "D")
    For Each subFolder In folder.subfolders
        If Split(subFolder, "\")(UBound(Split(subFolder, "\"))) = FolderName Then
            Sheets("Create Folders").Cells(myRow, "E") = subFolder
             
        End
        End If

        doFolder subFolder
    Next subFolder
Next myRow
End Sub
4

0 回答 0