Getting save as a file name in a word

In the code below, the file name is hardcoded, but I want the user to be able to select it.

I read about GetSaveAsFilename , but I get an error when using it: "method or element 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 the 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 
+6
source share
3 answers

In the dialog box, you can specify the default path, including the file name, for example

 Sub SaveName() Dim strFileName As String Dim StrPath As String 'provide default filename StrPath = "c:\temp\test.docx" With Dialogs(wdDialogFileSaveAs) .Name = StrPath If .Display <> 0 Then strFileName = .Name Else strFileName = "User Cancelled" End If End With MsgBox strFileName End Sub 
+4
source

I did not understand that Word does not have the GetSaveAsFileName or GetOpenFileName methods (which are in Excel). But this is not so. Instead, you can try SaveAs FileDialog ( 2003 , 2007 , 2010 ):

 Sub ShowSaveAsDialog() Dim dlgSaveAs As FileDialog Set dlgSaveAs = Application.FileDialog(FileDialogType:=msoFileDialogSaveAs) dlgSaveAs.Show End Sub 
+4
source
 Dim strFilePath, strFileName strFilePath = "C:\Users\Public\Documents\" strFileName = "put-filename-here.docx" With Dialogs(wdDialogFileSaveAs) .Name = strFilePath & strFileName .Show End With 
0
source

Source: https://habr.com/ru/post/914676/


All Articles