• Skip to primary navigation
  • Skip to main content
  • Skip to footer
WallStreetMojo

Wallstreet Mojo

Wallstreet Mojo

MENUMENU
  • Resources
        • Excel

          • Excel Functions
          • Excel Tools
          • Excel Tips
        • Excel
        • Financial Functions Excel

          • NPV in Excel
          • IRR in excel
          • PV in Excel
        • Financial-Functions-Excel
        • Lookup Functions Excel

          • VLOOKUP
          • HLOOKUP
          • Index Function
        • Lookup-Functions-in-Excel
        • Excel Charts

          • Pareto Chart in Excel
          • Gannt Chart in Excel
          • Waterfall Chart in Excel
        • Excel-Charts
        • VBA

          • VBA Left Function
          • VBA Paste Special
          • VBA Worksheet Function
        • VBA
        • Others

          • Resources (A to Z)
          • Financial Modeling
          • Equity Research
          • Private Equity
          • Corporate Finance
          • Financial Statement Analysis
  • Free Courses
  • All Courses
        • Certification Courses

          Excel Course certificate
        • Excel VBA All in One Bundle

          Excel-VBA-Certification-Course
        • Excel Data Analysis Course

          Excel-Data-Analysis-Course
        • VBA Macros Course

          VBA-Training-Course
        • Others

          • Basic Excel Training
          • Advanced Excel Course
          • Tableau Certification Course
          • Excel for Finance Course

          • Excel for Marketers Course
          • Excel for HR Managers
          • Excel for Power Users
          • View All
  • Excel VBA All in One Bundle
  • Login

VBA MsgBox

Home » VBA » VBA Message Functions » VBA MsgBox

By Roshan Waingankar Leave a Comment

VBA Message Box

MSGBOX function is like an output function which is used to display the generalized message provided by the developer, it is like a print statement for VBA, This function or statement has no arguments and the personalized messages in this function are written under the double quotes while the for the values the variable reference is provided.

Excel VBA MsgBox

When we start learning the very first thing we try to learn is VBA Message Box or MsgBox. MsgBox is nothing but a small box which holds the message to the user. In this tutorial, we are going to show you how to show message, how to customize message box, icon change, buttons change and other modalities of the message box.

MsgBox is part of the VBA in excel. If you are a new user of VBA nothing to worry we will introduce you to the VBA macro coding technique with MsgBox.

Firstly if you are not seeing Developer tab in your excel follow below steps to enable developer tab.

Step 1: Go to FILE > OPTIONS.

vbs msg box

Step 2: Click on Customize Ribbon under Excel Options.

vba msgbox 1

Step 3: On the right-hand side check the box Developer to enable it.

vba msgbox 2

Step 4: Click on Ok and close this window. Now you should see Developer tab in your excel ribbon.

vba msgbox 3

How to Create a VBA MsgBox?

Get started with creating a simple Excel VBA msgbox. We are going to display a simple excel VBA msgbox in the start-up.

You can download this VBA MSG Box Excel Template here – VBA MSG Box Excel Template

Follow the below steps to create a simple excel vba msgbox.

Step 1: Go to the DEVELOPER tab and click on VISUAL BASIC.

vba msgbox 4

Alternative: You can click the shortcut key ALT + F11.

vba macro shortcut key

Step 2: Now click on INSERT & insert MODULE.

vba msgbox 5

Step 3: It will insert the new MODULE in your VBA editor.

vba msgbox 6

Step 4: Start your macro by typing SUB which is the head of the macro. Give a MACRO a name and hit enter.

vba msgbox 31

Step 5: In between the Head & Tail of the macro we need to write the code. So start the word Msgbox it will display the MsgBox function.

Popular Course in this category
Cyber Monday Sale
VBA Training (3 Courses, 12+ Projects) 3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
4.6 (247 ratings)
Course Price

View Course

Related Courses

vba msgbox 8

Step 6: As soon as you see the word Msgbox press tab, it will start to show the Msgbox syntax.

vba msgbox 9

Step 7: Now type the word Welcome to VBA in double quotes.

vba msgbox 10

Step 8: We have created a simple excel vba msgbox macro. Now inside the macro place a cursor and press the key F5 which is the shortcut key to run a macro.

vba msgbox 11

Step 9: As soon as you run the macro you can see the VBA msgbox in your excel window.

vba msgbox 12

Structure of the Excel VBA Message Box

Now we know the method of showing a VBA msgbox. Now I will introduce you to the structure of the VBA Message Box. Message Box consists of four elements.

VBA Message Box specifications

The Syntax of  Excel VBA Message Box

Now we have seen the structure of the VBA MsgBox, each section of the VBA MsgBox is part of the syntax of the Excel VBA Message Box. As we type the word MsgBox we can see the syntax of the Excel VBA Message Box. Now I will introduce you to the MsgBox syntax.

vba msgbox 14

Prompt: This is the first and mandatory argument of the Excel VBA MsgBox. In the above example, I have to type the word “Welcome to VBA” as the Prompt. This is nothing but the message we need to show. We can show up to 1024 characters.

Button: This is nothing but what kind of button we need to show on the VBA MsgBox. For example, In our previous example, the default button showed as OK.

Title: This is the title of the VBA MsgBox. We can customize this title of the Excel VBA Message Box. We can give our own name to the message box in double quotes.

[help file]: This is nothing but the help icon you want to show to the users. If they have doubt and if you have already specified the suggestions then they can click on this hell file to learn more.

[Context]: This is the numerical value assigned to the appropriate help topic.

Excel VBA MsgBox with Title

By default message box displayed the title of the message box as Microsoft Excel. We can modify this as well. After the Prompt is supplied we can give our own name to the VBA MsgBox.

Step 1: First give Prompt i.e. message you want to show.

Syntax 15

Step 2: Now the next argument is Buttons ignore this and jump to the next argument i.e. Title.

vba msgbox 16

Step 3: We are done. Now run the macro by using F5 key.

Welcome 17

Now you can see the difference in the title of the message box. Instead of the default title Microsoft Excel now it is showing Introduction to VBA as the title of the message box.

Excel VBA Message Box Buttons

We have learned how to show a message box, how to alter the message box title. Now we will see the option of the message box button.

Once the prompt input is supplied next thing in the syntax is the message box button.

visual basic appplication 20

We have as many as 20 kinds of Excel VBA Message Box button options including Yes/No. You can select any one of the available 20 message box buttons. For example, I have selected vbYesNoCancel.

msgbox 21

Now run the macro we will see different message box button instead default OK button.

Result 22

Excel VBA Message Box Combination of Icon & Buttons

We have seen how to modify message box buttons. Along with the message box button, we can show icons as well like the below image.

Result 23

There are four kinds of icons available. vbCritical, vbQuestion, vbExclamation, and vbInformation.

In order to show the button along with the icon, we need to combine both by entering the plus (+) icon together.

#1 – vbQuestion Marks Icon

Code:

Sub SerialNumber ()
MsgBox “Welcome to VBA”, vbYesNoCancel + VbQuestion,”Introduction to VBA”
End Sub

Result:

Result 23               

#2 – vbCritical Marks Icon

Code:

Sub MessageBoxExample ()
MsgBox “Welcome to VBA”, vbYesNoCancel + VbCritical, “Introduction to VBA”
End Sub

Result:  

Result 25

#3 – vbExclamation Marks Icon

Code:

Sub MessageBoxExample ()
MsgBox “Welcome to VBA”, vbYesNoCancel + VbExclamation, “Introduction to VBA”
End Sub

Result:

Result 27

#4 – vbInformation Marks Icon

Code:

Sub MessageBoxExample ()
MsgBox “Welcome to VBA”, vbYesNoCancel + VbInformation, “Introduction to VBA”
End Sub

Result:

Result msgbox 29            

Things to Remember About VBA Message Box

  • We can combine both button and icon by combining with a plus (+) icon.
  • We combine many buttons by combining with a plus (+) icon.
  • As we progress to the next levels of VBA we will see the advanced message box options.
  • All the numerical prompt should be supplied with double quotes and numerical values do not require double quotes.

Recommended Articles

This has been a guide to VBA MsgBox. Here we learned how to create VBA Message Box (Yes/ No display, customize, change icons & buttons & other message box modalities. Below you can find some useful excel VBA articles –

  • VBA Not Function
  • Dictionary in VBA
  • UBOUND in Excel VBA
  • VLookup in Excel VBA
  • List Box in VBA Excel
  • Arrays in VBA Excel
  • Excel VBA Certification
0 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>

Filed Under: VBA, VBA Message Functions

Reader Interactions
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer
COMPANY
About
Reviews
Blog
Contact
Privacy
Terms of Service
FREE COURSES
Free Finance Online Course
Free Accounting Online Course
Free Online Excel Course
Free VBA Course
Free Investment Banking Course
Free Financial Modeling Course
Free Ratio Analysis Course

CERTIFICATION COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Business Valuation Course
Equity Research Course
CFA Level 1 Course
CFA Level 2 Course
Venture Capital Course
Microsoft Excel Course
VBA Macros Course
Accounting Course
Advanced Excel Course
Fixed Income Course
RESOURCES
Investment Banking
Financial Modeling
Equity Research
Private Equity
Excel
Books
Certifications
Accounting
Asset Management
Risk Management

Copyright © 2019. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.
WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Download VBA MSG Box Excel Template

By continuing above step, you agree to our Terms of Use and Privacy Policy.

CYBER WEEK OFFER - VBA Training Course (6 courses, 35+ hours video) View More