OzGrid

Excel Message Box (MsgBox) Function

< Back to Search results

 Category: [Excel]  Demo Available 

Excel Message Box (MsgBox) Function

 

THE MESSAGE BOX (MSGBOX) FUNCTION

How to capture which button the user clicked.

Option Explicit
'Message Box Syntax
'MsgBox(prompt[, buttons] [, title] [, helpfile, context])


Sub MsgBox_Static_Title_Msg()
'Move to very top of Module To make it _
    available to all Procedures within'
'Use as _
    Public Const strTitle As String = "Ozgrid.com" _
    At the very top of any Public Module to make _
    To all Public and Private Procedures
Const strTitle As String = "Ozgrid.com"
Const strMsg As String = "How are you feeling Today?"

'Run by placing cursor within Procedure & push F5
MsgBox strMsg, vbOKOnly, strTitle
End Sub


Sub MsgBox_Mix_Look()
'We can join looks and buttons by use of +

'Run by placing cursor within Procedure & push F5
    MsgBox "Hello Subscribers", vbInformation + vbOKOnly
End Sub


Sub Msgbox_Capure_Reply()
Dim lReply As Long


'Run by placing cursor within Procedure & push F5
    lReply = MsgBox("Do you wish to continue.", vbYesNoCancel + vbQuestion)

    Select Case lReply
        Case vbYes
          MsgBox "You chose Yes"
        Case vbNo
          MsgBox "You chose No"
        Case vbCancel
          MsgBox "You chose Cancel"
    End Select
          
End Sub


Sub Msgbox_Capure_Reply_Change_Default_Button()
Dim lReply As Long


'Run by placing cursor within Procedure & push F5
    lReply = MsgBox("Do you wish to continue.", vbYesNoCancel + vbQuestion + vbDefaultButton3)

    Select Case lReply
        Case vbYes
          MsgBox "You chose Yes"
        Case vbNo
          MsgBox "You chose No"
        Case vbCancel
          MsgBox "You chose Cancel"
    End Select
          
End Sub

 

See also:

Loop Through a Folder of Excel Workbooks
Mask Date Entry in Excel
Mask Time Entry in Excel
Minimize/Maximize Button to a UserForm
Excel VBA Macro Codes Tips & Tricks

 

See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 


Gallery



stars (0 Reviews)