Answers for "excel vba prevent save"

VBA
0

excel vba prevent save

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True 
    msgbox "Forbidden."
End Sub
Posted by: Guest on January-15-2021
0

excel vba prevent saving workbook

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True                       ' Cancels in any case
    ' Or :
    If SaveAsUI Then Cancel = True      ' Cancels only if saving is asked by user, not via code
End Sub

' Prevents Excel from requesting a save before closing
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.ThisWorkbook.Saved = True
End Sub
Posted by: Guest on January-17-2021

Code answers related to "VBA"

Browse Popular Code Answers by Language