How to Create a Dialog Box in Excel (3 Useful Applications)

While working in Excel, sometimes we need to show some results through a dialog box. These kinds of dialog boxes are introduced to show any disclaimer or to communicate with the user. In this article, I will show how to Create a Dialog Box in Excel.  I will show the whole procedure with the necessary steps and illustrations. I hope this article will help you to develop your Excel skill.


Download Practice Workbook

Please download the practice workbook from here to practice yourself.


Introduction to Dialog Box in Excel

Before jumping into the procedures, we need to know what a dialog box actually is. It will be easy for you to understand if I give an example. For instance, Consider a blank workbook or worksheet in Excel. In the ribbon of the Excel worksheet, some groups of commands may have more commands. But they are not showing this. To get all the programs, you need to click on the arrow on the rightmost downside. After that, a window will be opened with a lot of commands. This window may demand commands from your side to operate. This kind of popup window is called a Dialog Box. You can see an illustration of a dialog box given below.


3 Suitable Examples to Create a Dialog Box in Excel

In this part of the article, I will show some valuable applications for Creating a Dialog Box in Excel. Every example is easy, smart, and handy. So, without any further delay, let’s open an Excel worksheet and follow the steps in every example.


Example 1: Create a Simple Message Box

In this example, we will create a simple message box to convey a message. I will describe the steps with the necessary illustrations.

Steps:

  • First, open the Microsoft Visual Basic for Application by clicking Alt+f11.
  • Select the Insert tab on the Toolbar.
  • After that, Open a module.

Example 1 to create a dialog box in excel

  • Write down the following code in the module.
Sub Simplebox()
MsgBox “Hello Altruists!”
End Sub
  • Press f5 to run the code.

Example 1 to create a dialog box in excel

  • You will find the result just like the picture given below.

Example 1 to create a dialog box in excel

Read More: How to Work with Dialog Box in Excel (Types and Operations)


Example 2: Create an Interactive Dialog Box

In this portion, I will show how to Create an Interactive Dialog Box with some simple steps. Just follow my steps, and you will be also able to make an interactive dialog box.

Steps:

  • Write down the following code in the VBE.
Sub TestInputBox()
Dim R As Integer
R = MsgBox("Are you sure to press YES",vbYesNo)
If R =  vbYes Then
MsgBox (“You Pressed YES”)
Else
MsgBox (“You Pressed NO”)
End If
End Sub

Example 1 to create a dialog box in excel

  • Run the code by pressing f5.
  • A pop-up window just like the following will show the result. You have to press Yes or No

Example 2 to create a dialog box in excel

  • If you Press Yes, a window will show results just like the one given below.

Example 2 to create a dialog box in excel

  • If you press No, the popup window will show the following result.

Example 2 to create a dialog box in excel

  • To make attractive the interactive dialog box, write down the following code:
Sub TestInputBox()
Dim R As Integer
R = MsgBox("Are you sure to press YES",vbYesNo + vbQuestion)
If R =  vbYes Then
MsgBox “You Pressed YES”, vbInformation
Else
MsgBox “You Pressed NO”, vbCritical
End If
End Sub

  • Press the Run button to run the code.
  • After that, this window will occur and a new question mark will appear on the left side of the question.

Example 2 to create a dialog box in excel

  • If you press Yes, this icon will occur.

Example 2 to create a dialog box in excel

  • If you press No, another cross symbol will occur.

Example 2 to create a dialog box in excel

  • Moreover, to add the heading of every dialog box, write down the following code.
Sub TestInputBox()
Dim R As Integer
R = MsgBox("Are you sure to press YES",vbYesNo + vbQuestion, “YES or NO”)
If R =  vbYes Then
MsgBox “You Pressed YES”, vbInformation, “YES PLEASE”
Else
MsgBox “You Pressed NO”, vbCritical, “NO THANKS”
End If
End Sub

Example 2 to create a dialog box in excel

  • After that, Run the code by pressing f5.
  • Then, you will find a dialog box with the heading YES or NO.

Example 2 to create a dialog box in excel

  • After pressing Yes, you will find a popup window mentioning YES PLEASE.

Example 2 to create a dialog box in excel

  • After Pressing No, you will find another popup window with the heading NO THANKS.

Example 2 to create a dialog box in excel

Read More: How to Close Dialog Box in Excel (3 Easy Ways)


Example 3: Create a Dialog Box to Input Data in Excel

Here, I will show how to Create a Dialog Box in Excel more interactively and interestingly. Let’s see the process step by step.

Steps:

  • In the VBE, write down the following code:
Sub TestInputBox()
Dim R As String
R = InputBox("Write YES or NO", "YES or NO", "Enter your text HERE")
MsgBox R
End Sub

  • Run the code using the Run
  • You will find the popup window just like the one given below. You can see the headings and find a box to input your data.

  • Write down Yes in the input box.
  • After that, Press the OK

  • As a result, you will find the dialog box mentioning YES.

Read More: How to Display References Dialog Box in Excel


Things to remember

  • You need to bear in mind that, the whole procedure of creating a dialog box is done with VBA code. So, you should save the file by selecting the macro-enabled extensions.

Conclusion

I have tried my best to make you understand the procedure to Create a Dialog Box in Excel. Hope you have enjoyed the whole procedure. If you have any queries, let me know in the comment section.


Related Articles

Souptik Roy

Souptik Roy

Hello there. This is Souptik Roy. I graduated from Naval Architecture & Marine Engineering department. I am trying to explore the world of Microsoft Excel and want to increase my analytical power apart from my Engineering degree, as I have a curious mind. this is why I am trying to learn Excel Operations and write articles to help others.

We will be happy to hear your thoughts

Leave a reply

5 Excel Hacks You Never Knew

Genius tips to help you unlock Excel's hidden features

FREE EMAIL BONUS

ExcelDemy
Logo