Cancel button and X button in top right corner of message box 
Author Message
 Cancel button and X button in top right corner of message box

On my worksheet I have a message box that pops up when the workbook is
opened.  The message box has 2 command buttons.  The 1st one is an OK
button.  If this button is clicked, the workbook will remain open.  The 2nd
one is a CANCEL button.  If this button is clicked, the workbook will close.
However, if the user decides to click the X button at the top right corner,
the message box will go away but the workbook will remain open.  I do not
want the workbook to remain open even if the X button is clicked.

How can I prevent this?

I would like to either have the message box NOT have an X button or would
like to have the workbook close if the X button is clicked.  How can I do
this?



Fri, 11 Feb 2005 18:11:05 GMT  
 Cancel button and X button in top right corner of message box
Hi,

You could define a global boolean called bUserFormOK (at
the top of a Normal Module):

Global bUserFormOK as Boolean

Then in the code that shows the form:

Sub Whatever()
bUserFormOk=False
UserForm1.Show
If bUserFormOk=False then
' User has not clicked OK, quit
Thisworkbook.Close False
Else
'Do other stuff
End If
End Sub

And in the code behind the OK button:
Private Sub CommandButton1_Click()
bUserFormOK=True
End Sub

Regards,

Jan Karel Pieterse
Excel TA/MVP

Quote:
>-----Original Message-----
>On my worksheet I have a message box that pops up when
the workbook is
>opened.  The message box has 2 command buttons.  The 1st
one is an OK
>button.  If this button is clicked, the workbook will

remain open.  The 2nd
Quote:
>one is a CANCEL button.  If this button is clicked, the

workbook will close.
Quote:
>However, if the user decides to click the X button at the
top right corner,
>the message box will go away but the workbook will remain
open.  I do not
>want the workbook to remain open even if the X button is
clicked.

>How can I prevent this?

>I would like to either have the message box NOT have an X
button or would
>like to have the workbook close if the X button is

clicked.  How can I do
Quote:
>this?

>.



Fri, 11 Feb 2005 18:31:57 GMT  
 Cancel button and X button in top right corner of message box
This is really confusing to me.  Can you please break it down?



Quote:
> Hi,

> You could define a global boolean called bUserFormOK (at
> the top of a Normal Module):

> Global bUserFormOK as Boolean

> Then in the code that shows the form:

> Sub Whatever()
> bUserFormOk=False
> UserForm1.Show
> If bUserFormOk=False then
> ' User has not clicked OK, quit
> Thisworkbook.Close False
> Else
> 'Do other stuff
> End If
> End Sub

> And in the code behind the OK button:
> Private Sub CommandButton1_Click()
> bUserFormOK=True
> End Sub

> Regards,

> Jan Karel Pieterse
> Excel TA/MVP

> >-----Original Message-----
> >On my worksheet I have a message box that pops up when
> the workbook is
> >opened.  The message box has 2 command buttons.  The 1st
> one is an OK
> >button.  If this button is clicked, the workbook will
> remain open.  The 2nd
> >one is a CANCEL button.  If this button is clicked, the
> workbook will close.
> >However, if the user decides to click the X button at the
> top right corner,
> >the message box will go away but the workbook will remain
> open.  I do not
> >want the workbook to remain open even if the X button is
> clicked.

> >How can I prevent this?

> >I would like to either have the message box NOT have an X
> button or would
> >like to have the workbook close if the X button is
> clicked.  How can I do
> >this?

> >.



Fri, 11 Feb 2005 18:57:04 GMT  
 Cancel button and X button in top right corner of message box
Hi Todd:

I *think* Jan Karel might have misunderstood your question.

In a MessageBox, there should be no difference between clicking the Cancel
button, hitting the Esc key or clicking the "x". The following works fine
for me:

Private Sub Workbook_Open()
    If MsgBox("Test", vbOKCancel) = _
    vbCancel Then Me.Close
End Sub

Are you sure you are using a MessageBox and not a UserForm?
--
Regards,

Vasant.


Quote:
> This is really confusing to me.  Can you please break it down?



> > Hi,

> > You could define a global boolean called bUserFormOK (at
> > the top of a Normal Module):

> > Global bUserFormOK as Boolean

> > Then in the code that shows the form:

> > Sub Whatever()
> > bUserFormOk=False
> > UserForm1.Show
> > If bUserFormOk=False then
> > ' User has not clicked OK, quit
> > Thisworkbook.Close False
> > Else
> > 'Do other stuff
> > End If
> > End Sub

> > And in the code behind the OK button:
> > Private Sub CommandButton1_Click()
> > bUserFormOK=True
> > End Sub

> > Regards,

> > Jan Karel Pieterse
> > Excel TA/MVP

> > >-----Original Message-----
> > >On my worksheet I have a message box that pops up when
> > the workbook is
> > >opened.  The message box has 2 command buttons.  The 1st
> > one is an OK
> > >button.  If this button is clicked, the workbook will
> > remain open.  The 2nd
> > >one is a CANCEL button.  If this button is clicked, the
> > workbook will close.
> > >However, if the user decides to click the X button at the
> > top right corner,
> > >the message box will go away but the workbook will remain
> > open.  I do not
> > >want the workbook to remain open even if the X button is
> > clicked.

> > >How can I prevent this?

> > >I would like to either have the message box NOT have an X
> > button or would
> > >like to have the workbook close if the X button is
> > clicked.  How can I do
> > >this?

> > >.



Sat, 12 Feb 2005 10:01:50 GMT  
 Cancel button and X button in top right corner of message box
Hi Vasant

Quote:
> I *think* Jan Karel might have misunderstood your question.

> In a MessageBox, there should be no difference between clicking the Cancel
> button, hitting the Esc key or clicking the "x".

Since I knew that, I assumed it was a userform.

Regards,

Jan Karel Pieterse
Excel MVP



Sat, 12 Feb 2005 13:51:26 GMT  
 Cancel button and X button in top right corner of message box
Your right, I am using a user form.

Quote:
> Hi Todd:

> I *think* Jan Karel might have misunderstood your question.

> In a MessageBox, there should be no difference between clicking the Cancel
> button, hitting the Esc key or clicking the "x". The following works fine
> for me:

> Private Sub Workbook_Open()
>     If MsgBox("Test", vbOKCancel) = _
>     vbCancel Then Me.Close
> End Sub

> Are you sure you are using a MessageBox and not a UserForm?
> --
> Regards,

> Vasant.



> > This is really confusing to me.  Can you please break it down?



> > > Hi,

> > > You could define a global boolean called bUserFormOK (at
> > > the top of a Normal Module):

> > > Global bUserFormOK as Boolean

> > > Then in the code that shows the form:

> > > Sub Whatever()
> > > bUserFormOk=False
> > > UserForm1.Show
> > > If bUserFormOk=False then
> > > ' User has not clicked OK, quit
> > > Thisworkbook.Close False
> > > Else
> > > 'Do other stuff
> > > End If
> > > End Sub

> > > And in the code behind the OK button:
> > > Private Sub CommandButton1_Click()
> > > bUserFormOK=True
> > > End Sub

> > > Regards,

> > > Jan Karel Pieterse
> > > Excel TA/MVP

> > > >-----Original Message-----
> > > >On my worksheet I have a message box that pops up when
> > > the workbook is
> > > >opened.  The message box has 2 command buttons.  The 1st
> > > one is an OK
> > > >button.  If this button is clicked, the workbook will
> > > remain open.  The 2nd
> > > >one is a CANCEL button.  If this button is clicked, the
> > > workbook will close.
> > > >However, if the user decides to click the X button at the
> > > top right corner,
> > > >the message box will go away but the workbook will remain
> > > open.  I do not
> > > >want the workbook to remain open even if the X button is
> > > clicked.

> > > >How can I prevent this?

> > > >I would like to either have the message box NOT have an X
> > > button or would
> > > >like to have the workbook close if the X button is
> > > clicked.  How can I do
> > > >this?

> > > >.



Sun, 13 Feb 2005 16:55:57 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Disable Close Button (Big X in upper right corner)

2. Min/Full-Restore/Close Buttons on UserForms Upper Right-hand Corner

3. Upper Right Hand Corner X Button On Forms

4. How to disable the close window button in right corner of menu Bar in word

5. Disabling CommandBars and the x-button in the upper right corner

6. Disabling CommandBars and the x-button in the upper right corner

7. Disable the [x] button on right-up corner

8. Disabling CommandBars and the x-button in the upper right corner

9. Disabling CommandBars and the x-button in the upper right corner

10. Cancel button in Message Box


 
Powered by phpBB® Forum Software © phpBB Group