Re: Creating a directory from within Word VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Creating a directory from within Excel VBA
    ... I'm creating a little VBA script within Ms Excel, wanting the script to ... change directory before writing a file, ...
    (microsoft.public.excel.programming)
  • Creating a directory from within Word VBA
    ... I'm creating a little VBA script within Ms Word, wanting the script to ... change directory before writing a file, ...
    (microsoft.public.word.vba.general)
  • Re: how to bypass dialog box
    ... I've tried to open a corrupted Word File using the following ... Here is the script: ... Documents.Open {myfile}, OpenAndRepair:=True, ... need to be seriously modified so that it A) recognized the proper window creation ...
    (microsoft.public.word.vba.general)
  • Re: Problem with re module
    ... #BEGIN SCRIPT ... myfile = "raw.tex" ... fin = open ... %BEGIN TeX FILE ...
    (comp.lang.python)
  • Re: let built-in doesnt work as expected
    ... I have a file (myfile) containing the following lines: ... There are two problems with your script. ... The first problem can be solved by using redirection instead of ... cat; the second by reading the components of each line: ...
    (comp.unix.shell)