VBA get value returned by MsgBox
Solved
Code Jack
Posted messages
18
Status
Member
-
Yop73 -
Yop73 -
Hello everyone,
I'm unable to retrieve the value returned by a MsgBox into a variable myChoice. I need to know if the user wants to exit the step-by-step procedure...
Could you help me?
Thank you in advance,
Code Jack
Configuration: Windows 7 / Firefox 5.0
I'm unable to retrieve the value returned by a MsgBox into a variable myChoice. I need to know if the user wants to exit the step-by-step procedure...
Could you help me?
Thank you in advance,
Code Jack
Configuration: Windows 7 / Firefox 5.0
2 answers
-
Hello,
It all depends on your MsgBox...
Example with a "yes - no" message box:Sub test() Dim result As String, MyChoice As String result = MsgBox("Make your choice!", vbYesNo) If result = vbYes Then MyChoice = "Choice 1: Yes" Else MyChoice = "Choice 2: No" End If MsgBox MyChoice End Sub
--
Best regards,
Franck P -
That is exactly the type of request I have to make, thank you.
But the specific help regarding MsgBox:
"Returned values:
Constant, Value, Description
vbOK, 1, OK
vbCancel, 2, Cancel
vbAbort, 3, Abort
vbRetry, 4, Retry
vbIgnore, 5, Ignore
vbYes, 6, Yes
vbNo, 7, No"
I thought I needed to retrieve an integer in myChoice...
But if not, that's fine, I can work with your suggestion.
Thank you very much,
Code Jack-
-
-
What you raise is even more interesting to me because I've never asked myself the question and I've just realized that... I was completely wrong!!!!
MsgBox always returns an Integer... vbYes, for example, is a VBA constant equal to 6.
The mistake I've been making all along is automatically handled by VBA...
Dim result As String while actually result = 6 is processed automatically (I read it somewhere but where...???).
Sources: MsgBox -
-