VBA MkDir Folder

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,107
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm working with this code in producing a common file folder in the current directory.

Code:
Sub MakeMyFolders()



MkDir ThisWorkbook.path & "\mmyy"


End Sub

I'd like to use the Format(Now(), "mm-yy") to produce the current month and year for the file folder.

Can someone please help me out with this ??

Many thanks in advance!
Respectfully,
pinaceous
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try it like this...

Code:
MkDir ThisWorkbook.path & "\" & Format(Date, "mm-yy")
 
Upvote 0
Try it like this...

Code:
MkDir ThisWorkbook.path & "\" & Format(Date, "mm-yy")

Hi Domenic ?,

Okay, that's great ?

Now, how can I add a specific generic name to the title, adding onto the date format to the above code in producing the file folder name?

For example, if I want "ForestGump" to be placed in the title prior to your date format to produce "Forest Gump10-19". How can I do this?

Many thanks,
Paul

PS. Good to hear back from you ?
 
Upvote 0
Note that you are just sewing each piece of what you are building together with the ampersands (&). So to add hard-coded text, just add that piece in like:
Code:
MkDir ThisWorkbook.path & "[COLOR=#ff0000]\Forrest Gump[/COLOR]" & Format(Date, "mm-yy")
 
Upvote 0
Note that you are just sewing each piece of what you are building together with the ampersands (&). So to add hard-coded text, just add that piece in like:
Code:
MkDir ThisWorkbook.path & "[COLOR=#ff0000]\Forrest Gump[/COLOR]" & Format(Date, "mm-yy")

Hi Joe,

Thanks very much!

Paul
 
Upvote 0
Hi Joe4,
I have a question for you that came up.

What happens if "Forest Gump" is named in your workbook and you are referencing it in your code. How would you do that? How would you reference it?

For example, if "Forest Gump" is in Workbook(2) cell A77 how would you reference this here as the folder title in lieu of writing it out in your code?

How would you do this?

Many thanks,
Pinaceous
 
Upvote 0
Hi Pinaceous, try...

Code:
MkDir ThisWorkbook.path & "\" & workbooks(2).Worksheets("Sheet1").range("A77").value & Format(Date, "mm-yy")

Change the sheet name accordingly.
 
Upvote 0
Since we are on this subject, is there anyway to create a folder and subfolders within it?

For example, create folder "Movies" and then within it "Forest Gump" & "Harry Potter" based upon the code above? Or would this be two separate codes?

Please let me know, when you get a chance.

Thanks guys!
 
Upvote 0
Just keep using "MkDir" to make your directories.
You can use it more than once in your code.

Give it a try, and see how you do. If you run into issues, post your code attempt and we can help you clean it up.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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