Excel Office 365 VBA MsgBox – Use the Message Box Function!!
Tags: vbamacros, vbamsgboxinexcel
Published: 2020-12-16 12:32:56

---
title: Excel Office 365 VBA MsgBox – Use the Message Box Function!!
published: true
date: 2020-12-16 12:00:03 UTC
tags: VBAMacros,VBAMsgBoxinExcel
canonical_url: https://geekexcel.com/excel-office-365-vba-msgbox-use-message-box-function/
---

[VBA](https://geekexcel.com/excel-office-365-vba-overview-definition-and-examples/) MsgBox function is used to display any messages to the users in the form of a message box. You can use it by showing a custom message to your users. When the message box pops up, the user needs to click a button. After that, it returns an integer number that has been assigned to the specific button which is clicked by the user.

Here, we are going to see how to use **VBA MsgBox in Excel Office 365**.

## Jump To:

- [**VBA MsgBox – Syntax**](#1)
- [**Show Multiple Lines of String using MsgBox**](#2)
- [**Show Multiple Style MsgBox Dialog Box**](#3)
- [**A Brief Summary**](#4)

## VBA MsgBox – Syntax:

**MsgBox(prompt [,buttons] [,title] [help file,context])**

### Arguments Definition:

- **Prompt –** A string is displayed as a message in the dialog box. The maximum length of the prompt is approximately **1024 characters.**
- **Buttons –** It is an optional one. The values specifying the number and type of buttons to display. The **default value** for buttons is **0**.
- **Title –** An Optional parameter. The String expression displayed in the title bar of the dialog box. If you omit this option, the application name is placed in the title bar.
- **Help file –** It is an optional one. A String expression that identifies the Help file to use for providing context-sensitive help for the dialog box.
- **Context –** This is also an optional one. A Numeric expression that identifies the Help context number assigned by the Help author to the appropriate Help topic.

## Show Multiple Lines of String using MsgBox:

- First, you need to **open** the **Visual Basic Editor** by clicking the shortcut [**ALT** + **F11**](https://geekexcel.com/shortcut-to-open-vba-editor-in-microsoft-excel-365/) Keys.
- Then, on the **Insert Tab, select** the **Module** option from the menu.

![Insert Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Insert-Tab-20.png)<figcaption id="caption-attachment-19831">Insert Tab</figcaption>

- Then, you need to **enter the below given VBA code** in the code window.

VBA code to show multiple lines of strings using MsgBox

Sub multipleLineString()

Dim msgstr As String

msgstr = “Geek Excel” & Chr(13) & Chr(10)

msgstr = msgstr & “Welcome You!!” & vbCrLf

msgstr = msgstr & “Keep Learning”

MsgBox msgstr, ,”Greetings!!”

End Sub

- Finally, you need to **save the code.**

![Save the Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Save-the-Code.png)<figcaption id="caption-attachment-19832">Save the Code</figcaption>

- Now, you need to **close** this **window.**
- Then, go back to the workbook and **run** the **macro** by **clicking** the **Macros** option under the **Developer Tab.**

![Click Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Click-Macros-option.png)<figcaption id="caption-attachment-19833">Click Macros option</figcaption>

- Then, it will display the **Macro Dialog Box** , where you need to **select** the **macro name** and **hit** the **Run** button.

![Click the Run button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Click-the-Run-button.png)<figcaption id="caption-attachment-19834">Click the Run button</figcaption>

- Then, it will display the message box as shown in the below screenshot.

![Output](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Output-19.png)<figcaption id="caption-attachment-19835">Output</figcaption>

## Show Multiple Style MsgBox Dialog Box:

- You need to open the **VBA Editor**  by clicking the shortcut **ALT** + **F11** Keys.
- Then, you need to **insert** a **module.**

![Insert Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Insert-Tab-20.png)<figcaption id="caption-attachment-19831">Insert Tab</figcaption>

- Then, you need to **enter** the **following VBA code** in the code window.

VBA code to show multiple style MsgBox

Sub myMsgBoxEx2()

MsgBox “vbokCancel + vbCritical”, vbokCancel + vbCritical, “style1”

MsgBox “vbAbortRetryIgnore + vbQuestion”, vbAbortRetryIgnore + vbQuestion, “style2”

MsgBox “vbYesNo + vbInformation”, vbYesNo + vbInformation, “style3”

MsgBox “vbYesNoCancel + vbExclamation”, vbYesNoCancel + vbExclamation, “style4”

End Sub

- Now, you need to **save the code.**

![Enter the Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/1-27.png)<figcaption id="caption-attachment-19836">Enter the Code</figcaption>

- Then, you need to **close** this **window.**
- Then, go back to the workbook and **run** the **macro** by **clicking** the **Macros** option under the **Developer Tab.**

![Click Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Click-Macros-option.png)<figcaption id="caption-attachment-19833">Click Macros option</figcaption>

- Then, it will display the **Macro Dialog Box** , where you need to **select** the **macro name** and **hit** the **Run** button.

![Macro Dialog Box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/2-17.png)<figcaption id="caption-attachment-19837">Macro Dialog Box</figcaption>

- Then, it will **display the multiple style message boxes** as shown below.

#### Style 1 Message Box:

![Style 1 Message Box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Style-1-Message-Box.png)<figcaption id="caption-attachment-19838">Style 1 Message Box</figcaption>

#### Style 2 Message Box:

![Style 2](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Style-2.png)<figcaption id="caption-attachment-19839">Style 2</figcaption>

#### Style 3 Msg Box:

![Style 3](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Style-3.png)<figcaption id="caption-attachment-19840">Style 3</figcaption>

#### Style 4 Msg Box:

![Style 4](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Style-4.png)<figcaption id="caption-attachment-19841">Style 4</figcaption>

### MsgBox Function returns values as follows:

| Constant | **Value** | **Description** |
| --- | --- | --- |
| vbOK | 1 | OK |
| vbCancel | 2 | Cancel |
| vbAbort | 3 | Abort |
| vbRetry | 4 | Retry |
| vbIgnore | 5 | Ignore |
| vbYes | 6 | Yes |
| vbNo | 7 | No |

## A Brief Summary:

In the above article, we helped you to know how to use **VBA MsgBox in Excel Office 365**. Kindly, share your **feedback** in the comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!