Message Box in VBA

 

VBA MsgBox

The MsgBox is a dialog box in Excel VBA you can use to inform the users of your program.

Example: A simple message Box

MsgBox “Lets Learn VBA”

 A little more advanced message.

Display Value of Cell A1 using Message Box (First, enter a number into cell A1)

MsgBox “Value is ” & Range(“A1”).Value

 To Display the same, the value of Range A1 into next line

MsgBox “Entered Value is ” & vbNewLine & Range(“A1”).Value

Message Box with Advanced Parameters

Syntax

MsgBox(prompt[, buttons] [, title] [, helpfile, context])

Prompt: The message text which you want to show.

Buttons: The type of message box like Yes No buttons with Information Icon

Title: The title of the message box window

Helpfile, and Context are the other optional paramerter which we use in very rare

Example:

MsgBox “Hi Lets Learn VBA Message Box”, vbYesNo, “User Information”

MsgBox(“Continue Process…”, vbOKOnly + vbExclamation)

VBA MsgBox YesNo


To show the different messages boxes based on the selected option by user.

Sub test()

Dim x As Integer

x = MsgBox(“Continue the Process ?”, vbYesNo)

If x = vbYes Then

MsgBox “Continue….”

Else

MsgBox “Action Aborted…”

End If

End Sub

 

 

 

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/04/03/message-box-vba/
YouTube31
YouTube