Create a folder using Macro

Krishnakuma6

New Member
Joined
Mar 14, 2013
Messages
2
Dear Experts,​

I have data in column c in excel sheet, I want to create a folder in my network drive, Now I am using the following Code for that, but I have problem, Once I create a folder (including sub folders) and if I rename the some sub folders,then when I run the macro again the renamed sub folders are created again.I want to amend the code,if main folder is existing then no need to create a sub folders other wise create a main folder & sub folders

Sub CreateDirs()
Dim R As Range
Dim RootFolder As String
RootFolder = "J:\WORKWINNING\CLIENT 2013" '<<< CHANGE 1"
For Each R In Range("C162:C600") '<<< CHANGE 2
If Len(R.Text) > 0 Then
On Error Resume Next
MkDir RootFolder & "\" & "HQ " & R.Text
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Bid No Bid Form"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Clarification & Addenda"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Contract Award"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Contract Variation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Draft Tender Proposal"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Estimation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Expression of Interest"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Final Tender Proposal"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Post Tender Clarification & Meetings"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "PQQ"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Presentation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "RFP"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Site Visit Input"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Sub Contractor Proposal"
On Error GoTo 0
End If
Next R
MsgBox "Hi " & CreateObject("Outlook.application").Getnamespace("MAPI").CurrentUser & " Folder Created"
End Sub​
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Please give this a try:

Code:
Sub CreateDirs()
Dim R As Range
Dim RootFolder As String
RootFolder = "J:\WORKWINNING\CLIENT 2013" '<<< CHANGE 1"
For Each R In Range("C162:C600") '<<< CHANGE 2
If Len(R.Text) > 0 Then
If Dir(RootFolder & "\" & "HQ " & R.Text,vbDirectory)="" Then
On Error Resume Next

MkDir RootFolder & "\" & "HQ " & R.Text
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Bid No Bid Form"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Clarification & Addenda"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Contract Award"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Contract Variation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Draft Tender Proposal"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Estimation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Expression of Interest"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Final Tender Proposal"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Post Tender Clarification & Meetings"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "PQQ"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Presentation"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "RFP"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Site Visit Input"
MkDir RootFolder & "\" & "HQ " & R.Text & "\" & "Sub Contractor Proposal"
On Error GoTo 0
End if
End If
Next R
MsgBox "Hi " & CreateObject("Outlook.application").Getnamespace("MAPI").CurrentUser & " Folder Created"
End Sub
 
Upvote 0
Re: Create a folder using Macro (Solved)

Dear Firefly2012,
Thx for your quick reply,now it's working fine
K.murthy
 
Upvote 0

Forum statistics

Threads
1,207,402
Messages
6,078,270
Members
446,324
Latest member
JKamlet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top