MsgBox Prompt w/ No "X" to close

P

Pablo

hello:

this ng is great! Without _really_ knowing any "coding" I have been
able to patch together the following from postings in this group:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

' Prevents use of the Close button

If CloseMode = vbFormControlMenu Then
Cancel = True
ErrorBox = MsgBox("Would you like to close this workbook?",
vbYesNo, "Error")
If ErrorBox = YbYes Then
ActiveWorkbook.Close
ElseIf ErrorBox = YbNo Then
Cancel = True
End If
End If
End Sub


However, when I hit the run button, the form pops up, and if I click
the X in the top right corner of the form, the message box pops up. So
far so good.

But if I click on [Yes] it's no different than clicking [No]. [No]
does what I want, but [Yes] doesn't close the book.

Thanks for your help!
 
T

Tod

Try it this way:

Private Sub UserForm_QueryClose(Cancel As Integer,
CloseMode As Integer)

' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
Cancel = True
If MsgBox("Would you like to close this workbook?",
vbYesNo, "Error") = vbYes Then
ActiveWorkbook.Close
ElseIf ErrorBox = YbNo Then
Cancel = True
End If
End If
End Sub
 
G

Guest

You have the Eagle eye my friend. :0)
-----Original Message-----
the constant is
vbYes rather than YbYes and vbNo rather than YbNo

--
Regards,
Tom Ogilvy

Pablo said:
hello:

this ng is great! Without _really_ knowing any "coding" I have been
able to patch together the following from postings in this group:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

' Prevents use of the Close button

If CloseMode = vbFormControlMenu Then
Cancel = True
ErrorBox = MsgBox("Would you like to close this workbook?",
vbYesNo, "Error")
If ErrorBox = YbYes Then
ActiveWorkbook.Close
ElseIf ErrorBox = YbNo Then
Cancel = True
End If
End If
End Sub


However, when I hit the run button, the form pops up, and if I click
the X in the top right corner of the form, the message box pops up. So
far so good.

But if I click on [Yes] it's no different than clicking [No]. [No]
does what I want, but [Yes] doesn't close the book.

Thanks for your help!


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top