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.
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.
- First, open the Microsoft Visual Basic for Application by clicking Alt+f11.
- Select the Insert tab on the Toolbar.
- After that, open a Module.
- Write down the following code in the module.
Sub Simplebox() MsgBox “Hello Altruists!” End Sub
- Press f5 to run the code.
- You will find the result just like the picture given below.
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.
- 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
- 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
- If you press Yes, a window will show results like the one below.
- If you press No, the popup window will show the following result.
- 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.
- If you press Yes, this icon will appear.
- If you press No, another cross symbol will occur.
- 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
- After that, run the code by pressing f5.
- Then, you will find a dialog box with the heading YES or NO.
- After pressing Yes, you will find a popup window mentioning YES PLEASE.
- After pressing No, you will find another popup window with the heading NO THANKS.
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.
- 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.
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.