PDA

View Full Version : make directory



bacootje
04-13-2006, 04:09 AM
I have a list of 1000 cd`s in Excel sheet.
It contains :

Artist Titel
XXXXX XXXXXX

What i want is to make directories on my C: harddisk of all the 1000 cd`s of the list in Excel sheet.

Can please someboby help me.

Thanx
Bacootje

Bob Phillips
04-13-2006, 04:53 AM
Sub Test()
Dim iLastRow As Long
Dim i As Long
Const sRootDir As String = "C:\Music"

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
MkDir sRootDir
For i = 1 To iLastRow
On Error Resume Next
MkDir sRootDir & "\" & Cells(i, "A").Value
MkDir sRootDir & "\" & Cells(i, "A").Value & "\" & Cells(i, "B").Value
On Error GoTo 0
Next i

End Sub

Killian
04-13-2006, 04:55 AM
Hi Bacootje and welcome to VBAX :hi:

You can use the MkDir command to create a directory.
If you name the range in the Artist column "dirnames" and the Titel's are in the next column, this code will loop through and create the directories as "Artist - Titel"Sub MakeDirsFromRange()

Dim c As Range

ChDrive "C"
ChDir ("C:\")
For Each c In Range("dirnames")
MkDir (Trim(c.Text) & " - " & Trim(c.Offset(0, 1).Text))
Next

End SuThis does assume that these will all be unique names - if you try to create a directory that's already there, yopu'll get an error.
Let us know if you need to deal with that