
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?
> > >.