Name
Application.GetSaveAsFilename([InitialFilename
], [FileFilter
], [FilterIndex
], [Title
], [ButtonText
])
Synopsis
Displays the Save File As dialog box and returns a filename or False if no file is selected. Does not save the file.
Argument |
Setting |
---|---|
|
The name to display in the File text box |
Other arguments |
The following code saves the active workbook as a web page, closes the newly saved file, and reopens the original workbook in XLS format:
Sub TestGetSaveAs( ) Dim fname1 As String, fname2 As String, fname3 As String Dim fltr As String ' Save changes ActiveWorkbook.Save ' Get current filename. fname1 = ActiveWorkbook.Name ' Get filename for web page. fname2 = Replace(fname1, "xls", "htm") fltr = "Web page (*.htm),*.htm,XML data (*.xml),*.xml," & _ "XML Style Sheet (*.xsl),*.xsl" ' Show the Save As dialog. fname3 = Application.GetSaveAsFilename(fname2, fltr, _ 1, "Export to web") ' If not cancelled, save the file as a web page. If fname3 <> "False" Then _ ActiveWorkbook.SaveAs fname3, xlHtml ' Reopen the original file. Workbooks.Open fname1 ' Close the web page file. Workbooks(fname2).Close End Sub
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.