Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting save as file name in word

Tags:

ms-word

save

vba

In the code below the file name is hard coded, but I want the user to be able to pick it.

I was reading about GetSaveAsFilename but I get an error when using it: "method or member not found".

fileSaveName = Application.GetSaveAsFilename _
    (fileFilter:="Excel Files (*.txt), *.txt")

This is written for Word 2010. Am I wrong in thinking GetSaveAsFilename is available in word VBA?

 Sub Macro3()
'
' Macro3 Macro
'
'
    ActiveDocument.SaveAs2 FileName:="Questionnaire01-05-20122.txt", _
        FileFormat:=wdFormatText, LockComments:=False, Password:="", _
        AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
        :=True, SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, _
         AllowSubstitutions:=False, LineEnding:=wdCRLF, CompatibilityMode:=0
End Sub
like image 632
DevilWAH Avatar asked May 01 '12 21:05

DevilWAH


People also ask

What does ~$ mean in front of a file name?

From Wikipedia: “The tilde symbol is used to prefix hidden temporary files that are created when a document is opened in Windows. For example, when you open a Word document called “Document1. doc,” a file called “~$cument1. doc” is created in the same directory.

How can you change the file name using Save As?

Save a copy with a different name in a desktop appSelect File > Save As. Select where you want to save the file. Enter a new file name. Select Save.

Why do I get save a copy instead of Save As?

"Save a Copy" seems to make the most sense for today's workflows. Save A Copy: saves the document under a new name, but the original stays open for editing, not the new one. Save As: You save the document under a new name, and the new file stays open for editing.


1 Answers

I didn't realize that Word doesn't have GetSaveAsFileName or GetOpenFileName methods (which Excel has). But it doesn't. Instead you can try the SaveAs FileDialog (2003, 2007, 2010):

Sub ShowSaveAsDialog()
Dim dlgSaveAs As FileDialog
Set dlgSaveAs = Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.Show
End Sub
like image 174
Doug Glancy Avatar answered Sep 18 '22 11:09

Doug Glancy