ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MsgBox Prompt w/ No "X" to close (https://www.excelbanter.com/excel-programming/308242-msgbox-prompt-w-no-x-close.html)

Pablo

MsgBox Prompt w/ No "X" to close
 
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!

Tom Ogilvy

MsgBox Prompt w/ No "X" to close
 
the constant is
vbYes rather than YbYes and vbNo rather than YbNo

--
Regards,
Tom Ogilvy

"Pablo" wrote in message
om...
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!




tod

MsgBox Prompt w/ No "X" to close
 
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

-----Original Message-----
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!
.


No Name

MsgBox Prompt w/ No "X" to close
 
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" wrote in message
. com...
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!



.



All times are GMT +1. The time now is 11:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com