Contextures

Home > Macros > Basics > Messages

Show Messages With Excel Macros

Show 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.

edit a recorded macro

Show a Message in Excel

With a macro, you can show a message to people using an Excel workbook, to give helpful information or a warning.

Watch this video to see the steps for setting up an Excel message macro, and there are written steps below the video

Start Excel Message Macro

To create macros for some actions in Excel, you can use the built-in macro recorder.

  • Tip: If you haven't worked with Excel macro code before, there are Getting Started videos and written steps on the: Record and Test Macro page.

Unfortunately, you can’t record all the steps for creating a message, but you can use the Record Macro button to get started.

  1. In the Status Bar at the bottom left of the Excel window, click Record Macro
  2. Type a one word name for the macro, e.g. CustomerMessage
  3. Store the macro in ‘This Workbook’ and click OK
  4. In the Status Bar, click Stop Recording

See the Macro Code

Even though you didn't record any actions, Excel created a macro for you. To see the macro code, follow these steps:

  • On the Excel Ribbon, click the View tab, then click Macros
  • Click View Macros
  • In the list of macros, click on your macro’s name, then click Edit

The Excel Visual Basic Editor (VBE) opens, and you can see the macro. There are Sub and End Sub lines, and one comment line

macro code in Excel Visual Basic Editor

Add a Line of Code in Macro

You can’t record the code that shows the message box, so you’ll have to type it.

  • Click in the blank line between the Sub and End Sub lines.
  • Type this line of code:

Msgbox "Select a Customer Name"

Test the Message Macro

To see warning message that you created, switch back to Excel

  1. On the Excel Ribbon, click the View tab, then click Macros
  2. Click View Macros
  3. Click on your macro’s name, then click Run

The message will appear in the centre of the Excel window.

  1. Click OK to close the message.

message box with OK button

Edit Message Box Macro

That 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!

  • Go back to the VBE, to edit your macro.
  • Click at the end of the MsgBox line, and type a comma
  • A drop down list of options will appear, as well as a yellow tip box

list of message style options

  • Use the down arrow on your keyboard to select vbCritical
  • Press the Enter key to select that option

Test your macro again, to see the Critical icon in the revised message box.

message box with critical icon

Next Steps

In 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 Automatically

With 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 Printing

In 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 Name

In this macro, a personalized message includes a name.

edit a recorded macro

Watch this video to see the steps, and see the written instructions here: Show Personalized Excel Message Box.

Get the Sample Files

Show 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

Record and Test Macro

Add Code to Excel Workbook

Form Control Buttons

Worksheet Macro Buttons

Create an Excel UserForm

 

 

Last updated: May 14, 2023 1:19 PM