How to open the SAVE AS dialog box with VBA?

peter_z

Board Regular
Joined
Feb 27, 2011
Messages
87
Hey Guys,
Just wondering if anyone knows how to use VBA to open the save as dialog box?

I would like for the end user to be able to save the file and name the file to what ever they want.

Cheers for the help!
Peter
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Picking up further on the limits comment, for the actual SaveAs dialog you would use something like this

GetSaveAsFilename is used to get the name of a file - but it doesn't save the file by itself

Code:
Sub filesave()
    Dim bFileSaveAs As Boolean
    bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
    If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
End Sub
 
Upvote 0
Nice one cheers brettdj and repairman615 very helpful advice!
Got this report working nicely now :cool:
 
Upvote 0
This code works great for what I'm trying to do. Can you help me take it one step further. Is there a way to have a file name already in the saveas box that comes up. The file name I would like would come from 3 cells. A1_B1_C1 It is important to have the underscores between. I like this code because it gives the user the option to save it in a folder of their choice instead of a predefined one in a code.

Thanks!
 
Upvote 0
This code works great for what I'm trying to do. Can you help me take it one step further. Is there a way to have a file name already in the saveas box that comes up. The file name I would like would come from 3 cells. A1_B1_C1 It is important to have the underscores between. I like this code because it gives the user the option to save it in a folder of their choice instead of a predefined one in a code.

Thanks!

Just use the InitialFilename Optional Variant</STRONG>

following adpated from Helpfile.

Dave
Code:
Dim IntialName As String
Dim fileSaveName As Variant
InitialName = Range("A1") & "_" & Range("B1") & "_" & Range("C1")
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, _
    fileFilter:="Excel Files (*.xls), *.xls")

If fileSaveName <> False Then
    MsgBox "Save as " & fileSaveName
End If
 
Upvote 0
This code works great for what I'm trying to do. Can you help me take it one step further. Is there a way to have a file name already in the saveas box that comes up. The file name I would like would come from 3 cells. A1_B1_C1 It is important to have the underscores between. I like this code because it gives the user the option to save it in a folder of their choice instead of a predefined one in a code.

Thanks!
Code:
Application.Dialogs(xlDialogSaveAs) Range("A1").Text & "_" & Range("B1").Text & "_" & Range("C1").Text
 
Upvote 0
Thanks Dave! Where would I fit your code in with this the one from brettj?

Your code kind of works by itself but it is no saving nor showing any errors that it couldnt save!

The save dialog box will pop up with the data from the 3 cells and I click save, but when I goto the path on my computer that file is not there.

On another note how do you copy and paste code with the correct syntax when replying to a thread?
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top