Results 1 to 3 of 3
  1. #1
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stopping the 'x' (VBA)

    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'
    [img]/forums/images/smilies/cool.gif[/img] stop the 'x' from deactivating my form (hide is ok, deactivate is not)
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stopping the 'x' (VBA)

    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

  3. #3
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stopping the 'x' (VBA)

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

    Thx
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •