I'm trying to eliminate updating an open workbook from the "x" and "X" in the upper-right-hand corner of the Excel workspace.
So far I got the BeforeClose code (see below) and it works fine with 1 big exception.
Not only does it show the correct Msgbox for the "x" and "X" (which is correct), but also when I try to execute a workbook Update statement from within my form's code.
How can I negate the code below if the update is taking place from within my form?
(currently CloseMode is always 0 regardless of where the update is taking place).
One thought I had was to see if the form in question was currently visible (if NOT visible then the update request came from an "x" or "X"), but I can't get the code I had in mind to work.
Current code in ThisWorkbook of the opened workbook
Your help as always is greatly appreciated. You girls/guys do a great job of helping others solve their Excel problems.
<EDITED, code>
So far I got the BeforeClose code (see below) and it works fine with 1 big exception.
Not only does it show the correct Msgbox for the "x" and "X" (which is correct), but also when I try to execute a workbook Update statement from within my form's code.
How can I negate the code below if the update is taking place from within my form?
(currently CloseMode is always 0 regardless of where the update is taking place).
One thought I had was to see if the form in question was currently visible (if NOT visible then the update request came from an "x" or "X"), but I can't get the code I had in mind to work.
Current code in ThisWorkbook of the opened workbook
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If CloseMode = 0 Then
Cancel = True
MsgBox "Use MultiPages form to close workbook", OKOnly + vbInformation, _
"Attention !!!"
End If
End Sub
Your help as always is greatly appreciated. You girls/guys do a great job of helping others solve their Excel problems.
<EDITED, code>
Last edited by a moderator: