• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA disconnect workbook update via X ...

Frank M

New Member
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

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:
Hi, Frank M!
When posting code please do it between the proper tags "["Code"]" and "["/Code"]" (unquoted), also found in the response toolbar, 5th icon from the right. Thank you.
Regards!
 
Back
Top