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

ghp2017

New Member
Joined
Dec 12, 2017
Messages
49
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

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.
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,215,731
Messages
6,126,535
Members
449,316
Latest member
sravya

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