Force user to save with xlsm extension?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello, we've had several instance lately where users are opening a macro-enabled spreadsheet, completing it and then saving as with an xlsx extension.

Even though Microsoft pops up a message warning them that they'll lose macros, users are still going ahead.

is there a couple of lines of code I can put somewhere that simply stops them from saving with anything other than an xlsm extension?

Thanks for reading.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Did you try this?
 
Upvote 0
Did you try this?

yes - it doesn't work.

If I try to save my xlsm file as an xlsx file I simply get the standard Microsoft warning about "the following features cannot be saved in macro-free workbooks".
 
Upvote 0
yes - it doesn't work.

If I try to save my xlsm file as an xlsx file I simply get the standard Microsoft warning about "the following features cannot be saved in macro-free workbooks".

Ok, I managed to find this piece of code from this site around 9 years ago which does the trick :)
Code:
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim txtFileName As String
' Check if user has selected Save As
If SaveAsUI = True Then
Cancel = True
' Call modified dialog box. Cancel if user selects Cancels in the dialog box.
txtFileName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As XLSM file", "Excel Macro-Enabled Template (*.xltm), *.xltm"))
If txtFileName = "False" Then
MsgBox "Action Cancelled", vbOKOnly
Cancel = True
Exit Sub
End If
' file is saved as XLSM macro-enabled file
Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:=txtFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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