Avoid adding ".XLSM" to file name

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I am using this macro to save my workbook. The only issue I am having here is that; it adds “.xlsm” to the name.
How do I get rid of that?


Code:
Sub SaveAs()
    Dim FileSaveAs As String
    FileSaveAs = _
    Application.GetSaveAsFilename(FileFilter:="Exel Files(*.xlsm,*.xlsm", Title:="Select Name For File")
    
    If FileSaveAs <> "False" Then ActiveWorkbook.SaveAs FileName:=FileSaveAs, _
    Password:="", writerespassword:="", ReadOnlyRecommended:=False
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
The SaveAs method also takes in an argument for which you can specify the file format. So, for example, to specify the .xlsx file format, try...

Code:
ActiveWorkbook.SaveAs Filename:=FileSaveAs, FileFormat:=xlOpenXMLWorkbook

Although, you'll probably need to set the DisplayAlerts property to False before saving, and then back to True afterwards...

Code:
    If FileSaveAs <> "False" Then
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:=FileSaveAs, FileFormat:=xlOpenXMLWorkbook, _
            Password:="", writerespassword:="", ReadOnlyRecommended:=False
        Application.DisplayAlerts = True
    End If

Hope this helps!
 
Upvote 0
By the way, it looks like you've omitted a closing bracket...

Code:
[COLOR=#333333]FileFilter:="Exel Files (*.xlsm[/COLOR][COLOR=#ff0000])[/COLOR][COLOR=#333333], *.xlsm"[/COLOR]
 
Last edited:
Upvote 0
By the way, it looks like you've omitted a closing bracket...

Code:
[COLOR=#333333]FileFilter:="Exel Files (*.xlsm[/COLOR][COLOR=#ff0000])[/COLOR][COLOR=#333333], *.xlsm"[/COLOR]

Problem solved


How do I get the default location to point to the current location of the workbook I am saving?

Regards
Kelly
 
Last edited:
Upvote 0
Before GetSaveAsFilename,

Code:
chdrive activeworkbook.path
chdir activeworkbook.path
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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