PDA

View Full Version : Help with Creating directories & subdirectories



ads_3131
10-31-2008, 02:57 AM
Hello, Advancing on creating directories to also creating sub directories. Below is the code for Creating a directory from a list in column A. (which works) to create the directories i list, but below that i have found a code which helps to make subdirectories in a way but putting them together isn't working for me too well. Now that i have a list of what the directories are going to be in column A i need to put a list of the 1st subdirectory in column b, then 2nd in C and so on. It must be possible I just need help as i am all new and learning lol. Thanks

--------------------------------------------------------------
Public Sub ProcessData()
Const ROOT_FOLDER As String = "C:\Documents and Settings\Administrator\My Documents\Other\Test\"
Dim LastRow As Long
Dim i As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

On Error Resume Next
For i = 1 To LastRow

MkDir ROOT_FOLDER & .Cells(i, "A").Value

Next i
On Error GoTo 0
End With

End Sub

--------------------------------------------------------

Sub MakeDirectories()
' Declare variable for creating folders...
Dim Dir1 As String, Dir2 As String, Dir3 As String
' Assign directories location and its name...
Dir1 = "C:\MainFolder"
Dir2 = Dir1 & "\SubFolder1"
Dir3 = Dir1 & "\SubFolder2"
' Create folders...
On Error Resume Next
MkDir (Dir1)
MkDir (Dir2)
MkDir (Dir3)
On Error GoTo 0
End Sub

Bob Phillips
10-31-2008, 03:46 AM
Public Sub ProcessData()
Const ROOT_FOLDER As String = "C:\" '"C:\Documents and Settings\Administrator\My Documents\Other\Test\"
Dim LastRow As Long
Dim Folder As String
Dim i As Long
Dim j As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

On Error Resume Next
For i = 1 To LastRow

Folder = ROOT_FOLDER & .Cells(i, "A").Value
MkDir Folder
For j = 2 To .Cells(i, .Columns.Count).End(xlToLeft).Column

Folder = Folder & Application.PathSeparator & .Cells(i, j).Value
MkDir Folder
Next j
Next i
On Error GoTo 0
End With

End Sub

vpager
10-31-2008, 03:50 AM
In the first instance, I would suggest you take out the On Error Resume Next. Any errors caused by trying to create the directories will then be displayed to you.