Re: Creating a directory from within Word VBA
- From: "fumei via OfficeKB.com" <u37563@uwe>
- Date: Mon, 31 Mar 2008 19:14:57 GMT
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
.
- References:
- Creating a directory from within Word VBA
- From: Jo Gjessing
- Creating a directory from within Word VBA
- Prev by Date: RE: Replace causing repagination
- Previous by thread: Re: Creating a directory from within Word VBA
- Next by thread: add checkbox to table programatically
- Index(es):
Relevant Pages
|