fumei
Mon Mar 31 12:14:57 PDT 2008
While not disputing that you CAN do this:
"wanting the script to change directory before writing a file,"
I have to ask why? In actual fact, ChangeFileOpenDirectory does just that,
change the file OPEN directory. Yes, you can then save a file to that folder.
.but in a sense, who cares? You can save a file to anywhere you want,
anyway.
Here is an alternative example with explicit path and filename, and error
handling if the folder does not exist. You know it has to be the folder path,
as the filename is valid. It will accept anything really.
myNew.docagshlashlasuwj is a valid filename.
Dim myFile As String
Dim myPath As String
On Error GoTo yadda
myPath = "c:\do-dah\"
myFile = "myNew.doc"
ActiveDocument.SaveAs FileName:=myPath & myFile
yadda:
If Err.Number = 5152 Then ' there is no c:\do-dah
MkDir myPath ' so make c:\do-dah
ActiveDocument.SaveAs FileName:=myPath & myFile
End If
Jo Gjessing wrote:
>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
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200803/1