Group: microsoft.public.word.vba.general
From: "Doug Robbins - Word MVP"
Date: Monday, March 31, 2008 7:37 AM
Subject: Re: Creating a directory from within Word VBA

If you use the ChDir statement to try and change to a folder that does not
exist, it will return error number 76.

Hence, if you use the following code, it will create the folder:

On Error GoTo errHandler
ChDir "C:\this folder does not exist"

errHandler:
MsgBox Err.Number
If Err.Number = 76 Then
MkDir "c:\this folder does not exist"
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Jo Gjessing" wrote in message
news:6BECF5C1-0EB5-4E38-9685-C0628CE6BF34@microsoft.com...
> Hi all,
>
> I'm creating a little VBA script within Ms Word, wanting the script to
> change directory before writing a file, using the ChangeFileOpenDirectory
> method. It works fine. But what if the directory does not exist? Then I
> want
> the script to create it. Can you please tell me how I make it do so?
>
> Thank you very much in advance.
>
> Jo
>