I successfully used the below code to create a small number of folders. When triggered using a button on the spreadsheet it was working fine. Now that I have moved the code to trigger from a button (OK) within a userform, it is no longer working, displaying the error message 'Variable not defined', with the code stopping on "openAt".
I do not understand what appears to have changed.
Any help would be very much appreciated.
Thanks,
I do not understand what appears to have changed.
Any help would be very much appreciated.
Thanks,
VBA Code:
Private Sub cmdOk_Click()
openAt = "My computer:"
Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, "Please choose where to create the folder", 0, openAt)
On Error Resume Next
BrowseForFolder = ShellApp.Self.Path
MkDir (BrowseForFolder & "\" & Workbooks("Create folders & files").Worksheets("Tracker").Range("A2").value & _
"." & Right(Workbooks("Create folders & files").Worksheets("Tracker").Range("I2"), 4) & _
" - " & Workbooks("Create folders & files").Worksheets("Tracker").Range("E2").value)
MkDir (BrowseForFolder & "\" & Workbooks("Create folders & files").Worksheets("Tracker").Range("A2").value & _
"." & Right(Workbooks("Create folders & files").Worksheets("Tracker").Range("I2"), 4) & _
" - " & Workbooks("Create folders & files").Worksheets("Tracker").Range("E2").value & "\" & "DMP")
MkDir (BrowseForFolder & "\" & Workbooks("Create folders & files").Worksheets("Tracker").Range("A2").value & _
"." & Right(Workbooks("Create folders & files").Worksheets("Tracker").Range("I2"), 4) & _
" - " & Workbooks("Create folders & files").Worksheets("Tracker").Range("E2").value & "\" & "Previous similar requests")
End Sub