MACRO to save file as MACRO enabled worksheet while filename will be pulled from a cell

ghp2017

Board Regular
Joined
Dec 12, 2017
Messages
51
Hello,
I have a macro created to save the file but for some reason .xlsm is being included in the actual name of the file. Can anyone figure out how I can prevent that from happening?
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub SAVEAS()
'
' SAVEAS Macro
Dim save_as As Variant
Dim file_name As String


file_name = Sheets("Template").Range("D2")


' Get the file name.
save_as = Application.GetSaveAsFilename(file_name, _
FileFilter:="Excel Files,*.xlsm,All Files,*.*")
' See if the user canceled.
If save_as = False Then Exit Sub


' Save the file with the new name.
If LCase$(Right$(save_as, 4)) <> ".xlsm" Then
file_name = save_as & ".xlsm"
End If
ActiveWorkbook.SAVEAS Filename:=file_name
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
On this line
Code:
If LCase$(Right$(save_as, 4)) <> ".xlsm" Then
you are trying to check if the last 4 characters match a 5 character string & the answer will always be no.
Either change the 4 to a 5, or check xlsm (no .)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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