Home > Macros > Basics > Messages Show Messages With Excel MacrosShow warning messages in Excel workbook. Give automatic alerts, data entry tips. See steps in short videos, written steps. Get sample files with VBA code. Tip: For non-macro ways to show a message in Excel, you can add a comment to a cell, or use a data validation input message. |
Start Excel Message MacroTo create macros for some actions in Excel, you can use the built-in macro recorder.
Unfortunately, you can’t record all the steps for creating a message, but you can use the Record Macro button to get started.
|
See the Macro CodeEven though you didn't record any actions, Excel created a macro for you. To see the macro code, follow these steps:
The Excel Visual Basic Editor (VBE) opens, and you can see the macro. There are Sub and End Sub lines, and one comment line Add a Line of Code in MacroYou can’t record the code that shows the message box, so you’ll have to type it.
Msgbox "Select a Customer Name" Test the Message MacroTo see warning message that you created, switch back to Excel
The message will appear in the centre of the Excel window.
|
Edit Message Box MacroThat simple macro shows a message box, and the user will have to click the OK button before they can continue working in Excel. That will be a helpful reminder, but you can edit the message box, to give it more impact. Follow the steps below, to add a "Critical" icon to the message box. That might encourage people to take the message seriously!
Test your macro again, to see the Critical icon in the revised message box. Next StepsIn the next section, you'll see how to revise the macro again, so it only runs if the customer name in cell B5 is missing. In the section after that, you'll see how make the macro run automatically, if someone tries to print the worksheet, without a customer name selected |
Show a Message AutomaticallyWith a macro, you can show a message automatically, when something happens in Excel, to give information or a warning. Watch this video to see the steps, and see the written instructions here: Show a Message Automatically |
Show a Message Before PrintingIn this macro, a message shows automatically when someone tries to print the worksheet. Watch this video to see the steps, and see the written instructions here: Show a Message Before Printing |
Show Message with User NameIn this macro, a personalized message includes a name. Watch this video to see the steps, and see the written instructions here: Show Personalized Excel Message Box. |
Get the Sample FilesShow Personalized Message -- Download the workbook with code to show an Excel message box that includes the network username. The zipped file is in xlsm format, and contains the macro example from this page. |
Excel VBA Tutorials |
Last updated: May 14, 2023 1:19 PM