Try something like
Sub MakeMultiDir(FullPath As String)
Dim V As Variant
Dim N As Long
Dim S As String
V = Split(FullPath, "\")
For N = LBound(V) To UBound(V)
S = S & V(N)
If Dir(S, vbDirectory) = vbNullString Then
MkDir S
End If
S = S & "\"
Next N
End Sub
You can then call this with code like the following:
Sub AAA()
Dim S As String
S = "C:\Test2\TestSub1\TestSubSub1"
MakeMultiDir S
End Sub
MakeMultiDir will create any sub directories necessary in order to
make the full path specified by the FullPath parameter.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
On Thu, 3 Sep 2009 12:53:01 -0700, Orion Cochrane
wrote:
I need help making a directory if there isn't one present. I know you have to
use the mkdir command, but I don't know how to use it.
Here's an example:
I run a file, clear its contents, and save it. If I am clearing a December
file, I want a January file in a folder named 2010 in the current directory
and go up one folder (above the 2009 folder).
Basically, I need code to check whether a 2010 folder exists in a directory
path, and, if not, create it and save the file there.
TIA.