VBA to create new folder in current directory - parent name & date

Webbers

New Member
Joined
Oct 20, 2004
Messages
41
Hello all!

I have been doing this manually for a while and had a "duh" moment, that I should have a macro! This is something I felt I would store in my Personal workbook rather than within a project I am working on, as the need to use it on multiple projects is obvious. I need a macro that will allow me to create a new folder with specific criteria. Using folder paths names such as these are beneficial as I have Work in Progress files for all my active projects

1) Create the folder in the path of the workbook that I am actively working in
2) The folder name should be the name of the parent folder and today's date (format: " - mm-dd-yyyy"

C:\UserData\Z0041M7C\Documents\WAA Projects\Fringe Benefit Rates <!--- path of active workbook

File Name for folder: Fringe Benefit Rates - 4-22-2019

Because the path would change as my active workbook changes I do not want this hard-coded. Also, I would love to add error handling in case I already created the folder. I had 24 files in my folder for 4-19-2019.

I have seen many examples of creating file directories, but I have had difficulty converting them to meet my needs, as they all contain a hard coded path and file name. I need variables so I can use this script for every project I work on. Any help is greatly appreciated. Thanks.
 
Last edited by a moderator:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
It is not clear if you are trying to create a subdirectory or simply add a unique filename to the existing directory. To add a sub directory you would use the 'MkDir" method where as the unique filename can be handled with a 'SaveAs'. I understand that you want to run the macro from Personal Workbook, but being clear on what you are trying to create will save some time in developing the code.
 
Upvote 0
JLGWhiz,

I am sorry for the confusion... in my head it was clear, but obviously you cannot know what I am thinking. This will create a sub directory. So In my example, my active workbook would be in: C:\UserData\Z0041M7C\Documents\WAA Projects\Fringe Benefit Rates

The folder named: Fringe Benefit Rates

would be considered the parent directory and so that would be the name of the new folder (along with today's date. So once the new folder is created, it would have a path of:

C:\UserData\Z0041M7C\Documents\WAA Projects\Fringe Benefit Rates\Fringe Benefit Rates - 04-22-2019

Does that make sense? Did I cover all the missing information? So the new folder will always the same as the name of the parent folder with the date added.
 
Upvote 0
How about
Code:
Sub Webbers()
   Dim Pth As String, NewFldr As String
   
   Pth = ActiveWorkbook.Path
   NewFldr = "\" & Split(Pth, "\")(UBound(Split(Pth, "\"))) & Format(Date, " mm-dd-yyyy")
   If Dir(Pth & NewFldr, vbDirectory) = "" Then
      MkDir Pth & NewFldr
  End If
End Sub
 
Upvote 0
Fluff,

You are my hero (again!!). That is perfect! I cannot count the number of daily folders I have created manually on ever project for my work in progress to ensure as I add upgrades including new code to my files that I don't screw something up. As I mentioned, I normally have about 25 versions in each daily folder for each project. This is great. I have already created a button for my ribbon for macros. Thanks again, I really appreciate it.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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