Hi,
I am a new to VBA coding, and would appreciate some help. I am trying to create folders in a directory using data from one column, adding a space, then data from another column as a folder name. as an example data from column C + Space(1) + data from column E would make a folder named C E. I also want each folder to have four common sub directories. Here is the code I have compiled using other peoples VBA code. When I run the macro it gives me an error "run-time error 76, path not found" after the first couple of folders have been created.
I am a new to VBA coding, and would appreciate some help. I am trying to create folders in a directory using data from one column, adding a space, then data from another column as a folder name. as an example data from column C + Space(1) + data from column E would make a folder named C E. I also want each folder to have four common sub directories. Here is the code I have compiled using other peoples VBA code. When I run the macro it gives me an error "run-time error 76, path not found" after the first couple of folders have been created.
Code:
Sub MakeFolder()
Dim xdir As String
Dim fso
Dim lstrow As Long
Dim i As Long
Set fso = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To lstrow
xdir = "S:\Customer Files\" & Range("C" & i) & Space(1) & Range("E" & i).Value
If Not fso.FolderExists(xdir) Then fso.CreateFolder (xdir)
If Not fso.FolderExists(xdir & "\Drawings") Then fso.CreateFolder (xdir & "\Drawings")
If Not fso.FolderExists(xdir & "\Pictures") Then fso.CreateFolder (xdir & "\Pictures")
If Not fso.FolderExists(xdir & "\Manuals") Then fso.CreateFolder (xdir & "\Manuals")
If Not fso.FolderExists(xdir & "\Quotes") Then fso.CreateFolder (xdir & "\Quotes")
Next
Application.ScreenUpdating = True
End Sub
Last edited: