MsgBox Examples


Example 1 - vbInformation

Call MsgBox("MsgBox Prompt", _ 
            VBA.vbMsgBoxStyle.vbInformation + _
            VBA.vbMsgBoxStyle.vbYesNo, _
            "MsgBox Title")

Example 2

Dim iResult As VBA.vbMsgBoxResult 
iResult = MsgBox("MsgBox Prompt", _
                 VBA.vbMsgBoxStyle.vbInformation + _
                 VBA.vbMsgBoxStyle.vbOKOnly)

Example 3 - Multiple Lines

Call MsgBox("MsgBox Prompt" & _ 
            vbNewLine & _
            vbNewLine & _
            "Displayed over multiple lines", _
            VBA.vbMsgBoxStyle.vbInformation + _
            VBA.vbMsgBoxStyle.vbOKCancel)

Example 4 - vbExclamation

Call MsgBox("MsgBox Prompt", _ 
            VBA.vbMsgBoxStyle.vbAbortRetryIgnore + _
            VBA.vbMsgBoxStyle.vbExclamation + _
            VBA.vbMsgBoxStyle.vbMsgBoxRight)

Example 5 - vbQuestion

This time the default button has been changed.

Dim iResult As VBA.vbMsgBoxResult 
iResult = MsgBox("MsgBox Prompt ?", _
                 VBA.vbMsgBoxStyle.vbQuestion + _
                 VBA.vbMsgBoxStyle.vbYesNo + _
                 VBA.vbMsgBoxStyle.vbDefaultButton2)

Example 6 - vbCritical

Call MsgBox("MsgBox Prompt", _ 
            VBA.vbMsgBoxStyle.vbCritical + _
            VBA.vbMsgBoxStyle.vbYesNoCancel + _
            VBA.vbMsgBoxStyle.vbDefaultButton3 + _
            VBA.vbMsgBoxStyle.vbMsgBoxHelpButton)

If no help file has been given then the Help button does not do anything.


Example 7

Call MsgBox("Press the Help button for more help", _ 
            VBA.vbMsgBoxStyle.vbCritical + _
            VBA.vbMsgBoxStyle.vbYesNoCancel + _
            VBA.vbMsgBoxStyle.vbMsgBoxHelpButton, , _
            "C:\temp\Help.chm", 1)

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext