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

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.

You can use dialog boxes to show any disclaimer or to communicate with the user.


Watch Video – Create a Dialog Box in Excel


Introduction to Dialog Box in Excel

Before jumping into the procedures, we need to know what a dialog box 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 right-most 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.


How to Create a Dialog Box in Excel: 3 Suitable Examples

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: Dialog Box Launcher in Excel


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 can also 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 like the one 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 appear.

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


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 button.
  • 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 Input Dialog Box in Excel VBA 


Things to remember

You need to remember 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.


Download Practice Workbook

Please download the practice workbook from here to practice yourself.


Conclusion

I have described in this article how 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


<< Go Back to Excel Dialog Boxes | Excel PartsLearn Excel

Get FREE Advanced Excel Exercises with Solutions!
Souptik Roy
Souptik Roy

Souptik Roy, a BSc graduate in Naval Architecture and Marine Engineering from Bangladesh University of Engineering and Technology, dedicated 1.5 years to the ExcelDemy project. During this time, he authored 50+ articles and reviewed 20+ for ExcelDemy. Presently, he is a designer and content developer at YouHaveGotThisMath and Brainor, sister concerns of ExcelDemy. His educational content spans science, mathematics, and grammar. Roy's interests include developing creative ideas, visualizing concepts with tools like Adobe Illustrator, and problem-solving within Microsoft... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo