To save a workbook as XLSM in VBA, you can use the
SaveAs method. This method has various parameters that
allow you to specify the file format, file name, and
other options. For example, the following code saves the
active workbook as XLSM:
ActiveWorkbook.SaveAs Filename:="C:\MyWorkbook.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
You can also use the
Application.DefaultFilePath property to get the default
location for saving files. For example, the following code
saves the active workbook in the default location for
Excel workbooks:
ActiveWorkbook.SaveAs Filename:= _
Application.DefaultFilePath & "MyWorkbook.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
If you want to prompt the user for the file name and location,
you can use the
Application.GetSaveAsFilename method. This method displays
the standard Save As dialog box and gets a file name from
the user. For example, the following code displays the Save As
dialog box and saves the active workbook in the file format
that the user specifies:
ActiveWorkbook.SaveAs Filename:= _
Application.GetSaveAsFilename( _
fileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False