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)





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





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)