Application.GetSaveAsFilename HELP

McTavish14

New Member
Joined
Dec 5, 2012
Messages
18
Afternoon, I'm currently using the following (basic) code, but for some reason it doesnt actually save to any location. The actions all complete as expected, except for actually saving it.

Sub Xxxxx_SaveAs()
Application.GetSaveAsFilename

End Sub


The Save As window opens, the File name is populated as expected, the Save as type is All Files (*.*) and I am not sure if this is an issue (?).

Hit the Save button and you think all is done. However, you got to the save location and there is nothing.

Any help would be greatly appreciated.

I'm very much a novice when it comes to VBA!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try like this

Code:
Sub Xxxxx_SaveAs()
Dim fname
fname = Application.GetSaveAsFilename
ActiveWorkbook.SaveAs Filename:=fname
End Sub
 
Upvote 0
Try like this

Code:
Sub Xxxxx_SaveAs()
Dim fname
fname = Application.GetSaveAsFilename
ActiveWorkbook.SaveAs Filename:=fname
End Sub

This works a treat although it does error if you decide to Cancel your Save / Save As stating that A file named 'FALSE.xls' already exists in this location. Do you want to replace it? Selecting NO raises Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed.

Further, is there a way to default the Save as type to .xls?

Thanks for the help.
 
Upvote 0
Try this

Code:
Sub Xxxxx_SaveAs()
Dim fname
fname = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Save As")
If fname = False Then Exit Sub
ActiveWorkbook.SaveAs Filename:=fname
End Sub
 
Upvote 0
Try this

Code:
Sub Xxxxx_SaveAs()
Dim fname
fname = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Save As")
If fname = False Then Exit Sub
ActiveWorkbook.SaveAs Filename:=fname
End Sub


Superb! Thank you very much.

I've populated the "" with the desired filename prefix and this now works great.

One last question if I may please - could any of this code fail as a result of compatibility? The majority of my users will currently be using 2003, but we are ungoing a move to 2010.

Thanks again.
 
Upvote 0
That will work in Excel 2010 (just tested to be sure) but you might want to change .XLS to .XLSX or .XLSM if you want to save in an Excel 2010 file format. And you may need to specify the file type - see Use VBA SaveAs in Excel 2007-2010
 
Upvote 0

Forum statistics

Threads
1,215,337
Messages
6,124,340
Members
449,155
Latest member
ravioli44

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