PDA

View Full Version : Solved: Create folders if don't exist



MacDaddy
11-23-2009, 05:27 AM
Hi,

I'm using a macro to fire off a process where a master file is saved under a different name and in a different folder. Everything works as it should unless the target path contains folders that don't exists.

Is it possible to have the macro create any folders in the path that don't already exist?

This is needed for auditing purposes as the folders are based upon the month and year of parameter values passed by the user, I could create them in theory in advance but it would quickly become messy as I would have to create many many folders. It would be nice if Excel could recognise that folder(s) in the path do not exist and create them as required but I don't know if this feature exists within VBA.

Thanks in advance,

Paul

Bob Phillips
11-23-2009, 07:17 AM
On ERror Resume Next

MkDir "C:\Level1"
MkDir "C:\Level1\Level2"
MkDir "C:\Level1\Level2\Level3"
MkDir "C:\Level1\Level2\Level3\myDir"
On Error Goto 0

MacDaddy
11-23-2009, 08:00 AM
Great stuff, thank you so very much!