Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse VBA code and the Excel Save As dialog to get the name of a file in which to save a workbook
DescriptionThis example shows how to use VBA code and the Excel Save As dialog to get the name of a file in which to save a workbook.
KeywordsVBA, Excel, Save As, GetSaveAsFilename
CategoriesOffice, Files and Directories
 
Use the Application object's GetSaveAsFilename function. This function returns a Variant. If the user cancels, the return values is False. Otherwise it is the name of the file the user selected.
 
Private Sub cmdGetSaveAsName_Click()
Dim file_name As Variant

    ' Get the file name.
    file_name = Application.GetSaveAsFilename( _
        FileFilter:="Excel Files,*.xls,All Files,*.*", _
        Title:="Save As File Name")

    ' See if the user canceled.
    If file_name = False Then Exit Sub

    ' Save the file with the new name.
    If LCase$(Right$(file_name, 4)) <> ".xls" Then
        file_name = file_name & ".xls"
    End If
    ActiveWorkbook.SaveAs Filename:=file_name
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated