MsgBox Examples


Example 1 - vbInformation

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

Example 2

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

Example 3 - Multiple Lines

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

Example 4 - vbExclamation

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

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)
microsoft excel docs

Example 6 - vbCritical

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

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)
microsoft excel docs

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