Excel vba:创建文件夹不起作用

时间:2017-09-22 08:20:07

标签: excel vba excel-vba

我试图通过vba在测试文件夹中创建文件夹,但它不起作用。我无法弄清楚原因 - 这些命令似乎合法。

Option Explicit

Sub createFolders()
    Dim homePath As String
    Dim folderName As String
    Dim foldersNumber As Long
    homePath = ThisWorkbook.Worksheets("setup").Cells(1, 2).Value & "\"
    folderName = ThisWorkbook.Worksheets("setup").Cells(2, 2).Value

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")


    Dim i As Long
    For i = 1 To foldersNumber
            If Not fso.FolderExists(homePath & folderName & i) Then
                    fso.CreateFolder (homePath & folderName & i)
            Else
                MsgBox ("Folder exits")
            End If


    Next

    MsgBox ("DONE")
End Sub

0 个答案:

没有答案