sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm trying to find a way to close a Workbook through a Macro and prevent closing with the standard X in the corner of the application.
I have this so far;
This works fine, but it also triggers when I use the command I have put on the ribbon which is this;
What I need to achieve is to force the user to only be able to close the file using the button I've put on the ribbon and not the X in the corner.
Is there such a way?
I have this so far;
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Cancel = False Then
Call MsgBox("You must use the Close button on the menu to exit this file", vbCritical, "Button disabled")
Cancel = True
Exit Sub
End If
End Sub
This works fine, but it also triggers when I use the command I have put on the ribbon which is this;
Code:
Application.DisplayAlerts = False
If Workbooks.Count = 1 Then
Application.Quit
ActiveWorkbook.Close SaveChanges:=True
Else
ActiveWorkbook.Close SaveChanges:=True
End If
Application.DisplayAlerts = True
What I need to achieve is to force the user to only be able to close the file using the button I've put on the ribbon and not the X in the corner.
Is there such a way?