• Stopping the ‘x’ (VBA)

    Author
    Topic
    #401133

    Good Morning All,

    I have a little excel vba program that works perfectly as long as I can stop uses clicking the little ‘x’ in the top right of my forms. I thought that there was a way of setting the form so that it was a dialog box (or is that VB). Another thing I tried was intercepting the ‘x’ and stopping it. Didn’t work.

    So, how do I either:

    a) get rid of the ‘x’
    stop the ‘x’ from deactivating my form (hide is ok, deactivate is not)

    Viewing 1 reply thread
    Author
    Replies
    • #787846

      You can use the QueryClose event of the userform. It has two arguments:
      Cancel: set this to any value different from 0 to cancel closing the form.
      CloseMode: specifies what initiated the event. It can be
      – vbFormControlMenu: user clicked “x” or system menu in upper left corner of form.
      – vbFormCode: Unload called in code.
      – vbAppWindows: Windows is being shut down.
      – vbAppTaskManager: user tries to close Excel from Task Manager.

      So put this code in the QueryClose event:

      Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
      Cancel = (CloseMode = vbFormControlMenu)
      End Sub

      and make sure that you have a command button or something like that to close the form:

      Private Sub cmdClose_Click()
      Unload Me
      End Sub

      • #787860

        perfect – that should stop the stupid user from breaking all my hard work!

        Thx

      • #787861

        perfect – that should stop the stupid user from breaking all my hard work!

        Thx

    • #787847

      You can use the QueryClose event of the userform. It has two arguments:
      Cancel: set this to any value different from 0 to cancel closing the form.
      CloseMode: specifies what initiated the event. It can be
      – vbFormControlMenu: user clicked “x” or system menu in upper left corner of form.
      – vbFormCode: Unload called in code.
      – vbAppWindows: Windows is being shut down.
      – vbAppTaskManager: user tries to close Excel from Task Manager.

      So put this code in the QueryClose event:

      Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
      Cancel = (CloseMode = vbFormControlMenu)
      End Sub

      and make sure that you have a command button or something like that to close the form:

      Private Sub cmdClose_Click()
      Unload Me
      End Sub

    Viewing 1 reply thread
    Reply To: Stopping the ‘x’ (VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: