Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding what response codes come back from MsgBox

Tags:

vba

msgbox

I'm very new to programming and I'm just starting to learn VBA with excel. I came across on this website and did the examples here but I have question about this code:

I know the variables are declared using "Dim" statement "Message" here is the variable with a data type of integer. What I don't clearly understand is; what is the meaning of "6" here and "7". I believe they come from somewhere. But as I just started learning this program, I don't have any idea. Could you please tell me how it end up to "6" and "7". I believe there is some basis here

Private Sub CommandButton1_Click()
Dim message As Integer
message = MsgBox("Click Yes to Proceed, No to stop", vbYesNoCancel, "Login")
If message = 6 Then
Range("A1").Value = "You may proceed"
ActiveWorkbook.Activate 
ElseIf message = 7 Then
ActiveWorkbook.Close
End If

End Sub

Thank you for your help:-)

=======

Thanks guys for the answers, they're very helpful. Yes this thread has been already posted in superuser site. I was informed that this question should belong here so I posted it here after reading that they will do it automatically from superuser to stackoverflow.

thanks once again

like image 961
tintincutes Avatar asked Nov 18 '09 14:11

tintincutes


People also ask

What is the MsgBox function explain?

In an Access desktop database, the MsgBox Function displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.

What is message box () What are the various buttons that can be added to message box?

The VBA MsgBox function is used to display messages to the user in the form of a message box. We can configure the message box to provide the user with a number of different buttons such as Yes, No, Ok, Retry, Abort, Ignore and Cancel. The MsgBox function will then return the button that was clicked.

What is vbInformation in VBA?

vbExclamation. Shows the warning message icon. vbInformation. Shows the information icon.

What is vbCritical?

vbCritical. It displays a Critical Message icon. vbQuestion. It displays a Query icon. vbExclamation.


1 Answers

This link is for VBScript, but I think the return codes should be the same: MsgBox Function Reference

The Return Codes tell you which button was clicked:

1   OK
2   Cancel
3   Abort
4   Retry
5   Ignore
6   Yes
7   No
like image 129
Patonza Avatar answered Oct 23 '22 13:10

Patonza