Saturday, April 20, 2019

To run codes save this to
Thisworkbook

This coe is to save file as Exce XLSM or excel type macro

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

'1. Check of Save As was used.
   If SaveAsUI = True Then
        Cancel = True

'2. Call up your own dialog box.  Cancel out if user Cancels in the dialog box.
       txtFileName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As XLSM file")
        If txtFileName = "False" Then
            MsgBox "Action Cancelled", vbOKOnly
            Cancel = True
            Exit Sub
        End If
 
'3. Save the file.
       Application.EnableEvents = False
        ThisWorkbook.SaveAs Filename:=txtFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
        Application.EnableEvents = True
     
    End If
End Sub

No comments:

Post a Comment