TechCognition

Microsoft Visual Studio 2017 Promo Code
Microsoft Office 2016 Promo Code

Create Message Box and Call UserForm


In VBA MsgBox function creates a message box that displays information and it waits for user action before it closes. The basic MsgBox displays only simple message box which has OK and Cancel buttons. We can create custom message boxes by using VBA to display in Microsoft Office Excel.


Private Sub CommandButton1_Click()

    myTitle = "Open or Close UserForm"

    msg = "Do you want to Open UserForm"

    Response = MsgBox(msg, vbExclamation + vbYesNoCancel, myTitle)


    Select Case Response

        Case Is = vbYes

            frm.Show

        Case Is = vbNo

            frm.Hide

        Case Is = vbCancel

            Exit Sub

    End Select

End Sub


As shown above we are displaying Message Box with Yes, No, and Cancel buttons. On click on Yes we are displaying form, on No click hiding form and on Cancel click existing from functionality.


Add comment

Loading

© Copyright 2017 www.techcognition.com | Sitemap