Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a file in the current folder 1

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I am running WORD from the command prompt and would like to define a macro which saves the file in the current folder.

So, from the command prompt, in folder myfolder, I invoke WORD
C:\myfolder winword a1.doc

Within the WORD session I can click on File | Save. Word is all prepared to save the file into myfolder. Within the Save as window I can change the filename to a2.doc. The file is then saved into myfolder as C:\myfolder\a2.doc

I can save this sequence of instructions as a macro [blue]macsavea2[/blue]. The relevant VisualBasic code is :
ActiveDocument.SaveAs FileName:="a2.doc", FileFormat:=wdFormatDocument . . .

However if I then execute this macro, the file is saved, not in the current directory, but in :
C:\Documents and settings\Myname\My documents
and this is not what I want.

It appears that the behaviour of the macro is different to the behaviour of the same command sequence executed interactively.

How can I make the macro save the file into the current folder? I would mention that the WORD could be invoked from a different folder, so I do not wish to specify the path name explicitly.

I have tried using the CurDir() function, but this also returns C:\Documents and settings\Myname\My documents unless I have already saved a document in the current folder.
 

hi,

Your default file save path for Word is where it is saving.

Try this...
Code:
    with ActiveDocument
      .SaveAs FileName:=[b][highlight].Path & "\[/highlight][/b]a2.doc", FileFormat:=wdFormatDocument . . .
    end with

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
You are absolutely right, Skip. That does the trick and solves my problem.

Thank you very much. Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top