I need a Word2000 macro that will create a directory named "h:mso2000".
Thanks in advance!
I need a Word2000 macro that will create a directory named "h:mso2000".
Thanks in advance!

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
The entire macro consists of one line:
<pre>mkdir "h:mso2000"</pre>
So if you want an entire macro, with the name, it would consist of:
<pre>Sub MakeMyDirectory()
mkdir "h:mso2000"
End Sub</pre>
That's all.
I shoulda known that. How do I add a "mkdir if not exist" ? If the macro is run again, I get an error.
Something along the lines of:
<pre>If Len(Dir("h:mso2000")) Then
MsgBox "Directory already exists."
Exit Sub
End If
</pre>
should do.
Gary Frieder
www.CustomOfficeDev.com
Gotta remember that Len function! Great little tool!
Basically, I want the directory to be created if one does not exist. If one does exist, then nothing should happen (ie transparent to the user). Here is what I am trying:
Sub Create2000Directory()
'
' Create2000Directory Macro
' Macro created 5/24/2001 by W2KUSER
'
MkDir "h:mso2000"
If Len(Dir("h:mso2000")) Then
MsgBox "Directory already exists."
Exit Sub
End If
End Sub
When I run this the first time, I get the directory. When I run it the second time, I get a run-time error 75 Path/fil access error.
The order in the macro is not correct.
Try this:
<pre>Sub Create2000Directory()
'
' Create2000Directory Macro
' Macro created 5/24/2001 by W2KUSER
'
If Len(Dir("h:mso2000")) Then
MsgBox "Directory already exists."
Exit Sub
End If
MkDir "h:mso2000"
End Sub
</pre>
Or better yet this:
<pre>Sub Create2000Directory()
'
' Create2000Directory Macro
' Macro created 5/24/2001 by W2KUSER
'
If Len(Dir("h:mso2000")) Then
MsgBox "Directory already exists."
Else
MkDir "h:mso2000"
End If
End Sub
</pre>
You must test for existence of the directory before you attempt to create it. <img src=/S/joy.gif border=0 alt=joy width=23 height=23>
Tried your suggestion. Still get the same error if the directory exists. What am I doing wrong?
(BTW I really appreciate your help!)
Hi Artf,
Try:
If Dir("C:ZZZ", vbDirectory) = "" Then MkDir "C:ZZZ"
HTH,
Chris
My mistake. Change this:
If Len(Dir("h:mso2000")) Then
To
If Len(Dir("h:mso2000")) = 0 Then
I tested it, and it works.
It works perfectly. Nice and simple.
Thanks to all who offered suggestions.
That didn't seem to help. Maybe I'm doing something wrong. Chris Green's code did the trick.
Thanks for your quick responses.
You realize you are saying if the length of the directory name is 0, then it exists. That doesn't quite make sense.
FWIW
Try This:
<pre>Sub Create2000Directory()
''' Create2000Directory Macro
''' Macro created 5/24/2001 by JustCallMeAl
If Len(Dir("c:mso2000", vbDirectory)) > 0 Then
MsgBox "Directory already exists."
Exit Sub
Else
MkDir "c:mso2000"
End If
End Sub
</pre>
FWIW,
TomG