Prompt for Save As File Name

J

Jason

Hi, I am trying to prompt the user for the Save As file name, but I cannot
figure out how to accomplish this. In other words, I am looking for the Word
version of the Excel method:

Application.GetSaveAsFilename

TIA

Jason
 
J

Jason

Sorry, I meant to also state that this will need to work for both Word 97 and
Word 2003.

Jason
 
L

lwildernorva

The following methods should work in both Word 97 and 2003. From the
simplest to the most complex code, this first method will save the current
document to the current directory:

ActiveDocument.SaveAs

Note that if you have not yet saved the document, Word will simply assign it
a name in the "Doc1," "Doc2," etc. type format. If you've given the document
a name, it will use that name.

If you want the user to name the document to be saved, the following code is
necessary:

'Decllare your variable as a string
Dim myFilename As String
'Give your user an input box to enter the name of the file
myFilename = InputBox("Enter name you wish to assign to the file")
'Save the document using the file name assigned
ActiveDocument.SaveAs FileName:=myFilename

Again, using this code, the named file will be saved to the current
directory. If you want to change to a specific directory, use this code:

Dim myFilename As String
myFilename = InputBox("Enter name you wish to assign to the file")
'Change the directory path; make sure you enter the last backslash to
insure
'the file goes to the proper directory; since your directory path will
differ frmo 'the one used in the example, simply change the code to reflect
the correct 'directory on your computer
Application.ChangeFileOpenDirectory "C:\Documents and
Settings\leew\Protected Documents\"
ActiveDocument.SaveAs FileName:=myFilename

Finally, if you want the user to have control over both the filename and the
directory to which it is to be saved, the following code does that:

Dim myFilename As String
Dim myDirectory As String
myFilename = InputBox("Enter name you wish to assign to the file")
myDirectory = InputBox("Enter path, including any subfolders, where to
save file; i.e., 'C:\Documents and Settings\leew\Protected Documents\'")
ActiveDocument.SaveAs FileName:=myDirectory & myFilename

Hope this is helpful!
 
J

Jason

Thank you very much for the reply. Yes, that does help. I guess there is no
code that will work for both versions that allow the user to browse to the
appropriate directory? I just assumed that since this was an option in Excel,
it would also be an option in Word. I really wanted to avoid using an input
box unless absolutely necessary (to avoid spelling errors, etc.).

Jason
 
L

lwildernorva

Sorry, I think I may have misunderstood what you were trying to do. I think
this code will take care of the problem:

Sub ShowSaveAsDialog()
Dialogs(wdDialogFileSaveAs).Show
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top