1

I'm trying to create folders in a test folder through vba, but it doesn't work. I can't figure out why - the commands seem legal.

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
Ans
  • 1,212
  • 1
  • 23
  • 51
  • 7
    foldersNumber seems to be undefined. It is declared but never given a value, I suspect the for loop is never run. – AndyW Sep 22 '17 at 08:23
  • @ AndyW Thanks, I didn't notice that, was concentrating on a `fso` part. – Ans Sep 22 '17 at 08:36

0 Answers0