How to Display a Message Box in Excel Using VBA

Save

Being able to display message boxes from your Excel application can really make a difference in how users use your application. In Visual Basic for Applications, or VBA, you can use the "MsgBox" function to prompt messages directly from your program. Message boxes are also commonly used in computer programming to report error messages. Displaying friendly error messages can inform users on what steps they can take to fix a particular error.

  • Launch Microsoft Office Excel, click the "Developer" tab and click "Visual Basic" to open the VBA Editor window.

  • Press "Alt," "I" and "M" to insert a new code module.

  • Copy and paste the following code to create a new sub-procedure that displays a message box using VBA code:

    Private Sub displayMessageBox()

    On Error GoTo Err_displayMessageBox:

    MsgBox "Display message box in Excel using VBA", vbInformation, "Test Message"

    Exit_displayMessageBox:

    Exit Sub

    Err_displayMessageBox:

    MsgBox Err.Description

    Resume Exit_displayMessageBox:

    End Sub

  • Click the "Run" menu, then click "Run Sub/UserForm" to run your procedure and display the message box.

References

  • Photo Credit Dynamic Graphics/Dynamic Graphics Group/Getty Images
Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!