View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Create File Folder

Private Sub CommandButton1_Click()
Dim i As Long
Dim cLastRow As Long

cLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = 1 To cLastRow
mkdir cells(i,"A").Value
Next i

End Sub

This assumes your folder names start in A1, and go down column A, and that
the folder E:/customers and contacts/exists already.

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
...
Fredrik

Thanks, but how do I add the company name on each row of
my worksheet to the end of E:/customers and contacts/

I need to get for example

E:/customers and contacts/companyA
E:/customers and contacts/companyB
E:/customers and contacts/companyC

This will all come from column F on my worksheet.

Thanks in advance

Andy
-----Original Message-----

"Andy" wrote in

message
...
I am new to this VBA thing so any help would be

welcome.

I need to create a file folder for all of the companies
listed in column F of my worksheet. I have a button on
the worksheet with the following line of code attached
but can not see how to move down to the next row.

Also is there a way to check if the folder exists, if

it
does to ignore it and move to the next row.

Thanks

Andy


Private Sub CommandButton1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.createfolder("E:/Customers and Contacts/")

a.Close


End Sub


This is what I found. It looks pretty similar to your

code except for the
"/" you have at the end of the path. Remove it and see

what happens. Oh,
make sure the folder doesn't exist when you run the

code. You may want to do
that in your code in order to avoid errors.
Sub CreateFolder
Dim fso, fldr
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.CreateFolder("C:\MyTest")
Response.Write "Created folder: " & fldr.Name
End Sub/Fredrik


.