Mkdir

G

Greg

I'm trying to get this function to work, can anyone help

Function Make_Project_Directory(StrDrive, strProject_Directory,
strYear_Directory, strProject_Number)
Dim strProjectPath As String
'Dim result As String
strProjectPath = StrDrive & "\" & strProject_Directory & "\" & _
strYear_Directory & "\" & strProject_Number & "\" & _
"Current_Issue\"
MsgBox Len(Dir(strProjectPath, vbDirectory)) > 0
If Len(Dir(strProjectPath, vbDirectory)) > 0 Then
MsgBox "Directory " & strProjectPath & " already exists"
Else
MkDir strProjectPath
MsgBox "Directory " & strProjectPath & " has been created"
End If
End Function


Public Sub Test()
Make_Project_Directory "C:", "PLD Test", "07-08", "Project"
End Sub


Thanks for any help
 
J

Jeanette Cunningham

Greg,
MkDir cannot create multiple levels of directories.
If you need to create multiple levels of directories, call MkDir for each
level.


Jeanette Cunningham
 
S

Stuart McCall

Greg said:
I'm trying to get this function to work, can anyone help

Function Make_Project_Directory(StrDrive, strProject_Directory,
strYear_Directory, strProject_Number)
Dim strProjectPath As String
'Dim result As String
strProjectPath = StrDrive & "\" & strProject_Directory & "\" & _
strYear_Directory & "\" & strProject_Number & "\" & _
"Current_Issue\"
MsgBox Len(Dir(strProjectPath, vbDirectory)) > 0
If Len(Dir(strProjectPath, vbDirectory)) > 0 Then
MsgBox "Directory " & strProjectPath & " already exists"
Else
MkDir strProjectPath
MsgBox "Directory " & strProjectPath & " has been created"
End If
End Function


Public Sub Test()
Make_Project_Directory "C:", "PLD Test", "07-08", "Project"
End Sub


Thanks for any help

As Jeanette mentioned, VBA's Mkdir function is limited to one directory
level per call. However, we can roll our own function to accomplish this:

http://www.smccall.demon.co.uk/Strings.htm#CreatePath

Dim ErrNum As Long

ErrNum = CreatePath(strProjectPath)
If ErrNum = 0 Then
MsgBox "Path successfully created."
Else
MsgBox "Path was not created. The error number was " & ErrNum
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top