FSO。重命名子文件夹(循环)

时间:2019-04-30 08:09:10

标签: excel vba fso

我想遍历所有子文件夹并将其重命名为“ example”。我不知道所有子文件夹的文件夹名称。我的代码根本不起作用。

文件夹结构示例:

Main Folder >Subfolder A > Subfolder 1 (Rename this)
                >Some file
            >Subfolder B > Subfolder 2 (Rename this)
                >Some file
            >...

代码如下:

    Dim FSO As Object
    Dim folder As Object
    Dim subfolders As Object
    Dim MyFile As String
    Dim wb As Workbook
    Dim CurrFile As Object
    Dim NewFolderName As String
    NewFolderName = "Photos"

With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
End With

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set folder = FSO.GetFolder("C:\Users\Tom\Desktop\Test\SHeets\")
    Set subfolders = folder.subfolders


        For Each folder In folder.subfolders

        subfoldersName = folder.Path
        Application.StatusBar = subfoldersName


        Name subfoldersName As FolderName & NewFolderName    ' change the folder name

        Next



    Set FSO = Nothing
    Set folder = Nothing
    Set subfolders = Nothing

With Application
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With

End Sub

0 个答案:

没有答案