VBA search for a specific subfolder in many folders and move all the files in it

前端 未结 2 1812
天涯浪人
天涯浪人 2021-01-29 06:16

can you help me?

i want a macro vba that search for a SPECIFIC subfolder for example (Xfolder) between all the folders and subfolders that exist and mov

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 06:43

    To found some folder use something like this

    Sub findFolder()
    
        Dim searchFolderName As String
        searchFolderName = "somePath"
    
        Dim FileSystem As Object
    
        Set FileSystem = CreateObject("Scripting.FileSystemObject")
    
        doFolder FileSystem.getFolder(searchFolderName)
    
    
    
    End Sub
    
    Sub doFolder(Folder)
        Dim subFolder
        On Error Resume Next
        For Each subFolder In Folder.subfolders
            If Split(subFolder, "\")(UBound(Split(subFolder, "\"))) = "testFolder" Then
                MsgBox "gotcha"
            End
            End If
    
            doFolder subFolder
        Next subFolder
    
    End Sub
    

    And then you can do whatever with that folder and its content. So with i little use of google (one maybe two words) you can achieve what you wana

提交回复
热议问题