How does one convert vbyes / Vbno to boolean in VBA Excel?
How does one convert vbyes / Vbno to boolean in VBA Excel?
This code displays a msgbox and asks a question. The result get returned in a VbMsgBoxResult and I then convert it to boolean.
Dim gobox as VbMsgBoxResult
dim go as boolean
gobox = MsgBox("Question?", vbYesNo, "Descriptive Titel")
If gobox = vbYes Then
go = True
Else
go = False
End If
Is there a easier way to convert VbMsgBoxResult to Boolean?
1 Answer
1
Maybe just
go = (MsgBox("Question?", vbYesNo, "Descriptive Titel") = vbYes)
I do not think so. VbMsgBoxResult is an enumeration with seven values.
– Storax
Aug 30 at 9:29
Ahh so that type covers also other msgbox types like YesNoCancel ect. got it. Thank you for the quick reply.
– Lucas Raphael Pianegonda
Aug 30 at 9:32
yes, just have a look in the object browser (press F2 in the VBE for that) and search for VbMsgBoxResult.
– Storax
Aug 30 at 9:33
I guess you could also use
go = MsgBox("Question?", vbYesNo, "Descriptive Titel") - 7
as vbYes
= 6, vbNo
= 7, True
= -1 and False
= 0 (I'll add that I wouldn't as the answer given is easier to read).– Darren Bartrup-Cook
Aug 30 at 9:49
go = MsgBox("Question?", vbYesNo, "Descriptive Titel") - 7
vbYes
vbNo
True
False
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Yeah that works.. Still not sure if there is a way to really convert them into oneantoher without the comparison.. But definetly much shorter.
– Lucas Raphael Pianegonda
Aug 30 at 9:24