How to Create Message Box in Excel VBA Macros (5 Examples)

Welcome to Excel Avon

What is Message Box in Excel

Message Box is one of the most frequently used Functions in VBA Macro. VBA (MsgBox) is an inbuilt dialog box window that displays or displays a message alert box containing an optional set of buttons, icons and other logic settings Message box title: This is commonly used to display what VBA What is the message box about. In this article, we are going to show you how to create custom message boxes in Microsoft Excel using VBA.

How to Create Message Box in Excel

DOWNLOAD EXCEL FILE FROM HERE

Like functions and formulas in Excel, there is also the MSGBOX function. So let’s see how to make a message box. In this example, we want to create a dialog box just to say “this is simple message hello world”.

First we have to click on Visual Basic in Developer tab. You can also press Alt + F11.

message-box-in-excel

You should now have the VB editor open. In Project Explorer, you will find your workbook file listed. Now go to the Insert tab and insert the module.

message-box-in-excel (2)

This will create a new blank module.

message-box-in-excel

In the code window, we will type “Text_Messagebox()”. And you press Enter then Excel adds the “End Sub” line below this line. Now whatever code we will write it should be between these two lines.

message-box-in-excel .png3

Now let us add a comment which will make it easy to understand why we are typing the code here.

message-box-in-excel .png4

We type our MsgBox function.

message-box-in-excel5

Now we will click the Run button or you can also run the macro by pressing F5.

message-box-in-excel5 2

After clicking run button we will see our message box.

message-box-in-excel5 3

Note that now we add OK cancel button in this message box while “OK” is the default button. Let’s go to VB Editor

message-box-in-excel5 4

Now we will click the Run button or you can also run the macro by pressing F5. Code Run button as we mentioned below. 

After clicking run button we will see our message box.

run-button-message-box

Selecting a different button in msgbox

Click Cancel Button for close the msgbox window, now let’s see by adding Yes, No button.

run-button-message-box52

Now we will click the Run button or you can also run the macro by pressing F5.

After clicking run button we will see our message box.

run-button-message-box21

We will close the pop-up window of this message box and then see the icon with the button and will also add the question icon along with the Yes, No button in the pop-up window

run-button-message-box22

Again, we will click the Run button or F5.

After clicking run button. You can see that the question icon has been added in the pop-up window.

run-button-message-box23

We will remove the question icon and then we will add the information icon. 

run-button-message-box212

Again, we will click the Run button or F5. After clicking run button. You can see that the Information icon has been added in the pop-up window.

run-button-message-box231

Now we will add the message box title.

run-button-message-box20

Again, we’ll click the Run button or F5. After clicking on the Run button. You may notice that the information title, icon, and yes, no button has been added to the pop-up window.

run-button-message-box202

Learn More Topic in VBA  here

DOWNLOAD EXCEL FILE FROM HERE

So, I hope you have understood How to Use Message Box in Excel VBA Macros and for more information, you can follow us on Twitter, Instagram, LinkedIn, and YouTube as well.

You can also see well-explained video here

Leave a Reply