Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Forcing to save excelfile as .xlsm

Latest post Tue, Nov 11 2008 7:37 AM by SWEDOOR. 2 replies.
  • Tue, Nov 11 2008 3:41 AM

    • SWEDOOR
    • Top 500 Contributor
    • Joined on Fri, Feb 1 2008
    • Posts 2
    • Points 26

    Forcing to save excelfile as .xlsm

    J don't want the user to save excelfile as .xls/.xlsx/.xlsb ...

    Is it possible to force saving a excelfile as .xlsm using VBA?

    Filed under:
    • Post Points: 21
  • Tue, Nov 11 2008 6:59 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 543
    • Points 9,287
    • MVP

    Re: Forcing to save excelfile as .xlsm

    You could probably 'hijack' the save process with the Workbook_BeforeSave event.

    This would allow you to display your own dialog with only xlsm as an option and then ensure the selected name and file were saved as such. Like so:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim fName As String

    fName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")
    If fName = "False" Then
    MsgBox "You pressed cancel", vbOKOnly
    Cancel = True
    End If

    Application.EnableEvents = False
    ThisWorkbook.SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Application.EnableEvents = True

    End Sub

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    Filed under:
    • Post Points: 21
  • Tue, Nov 11 2008 7:37 AM In reply to

    • SWEDOOR
    • Top 500 Contributor
    • Joined on Fri, Feb 1 2008
    • Posts 2
    • Points 26

    Re: Forcing to save excelfile as .xlsm

    Thank you!

    It works for me!

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.