Message Box Issues

tzw1378

Active Member
Joined
Jan 16, 2014
Messages
270
Hello,

I have no idea what's going on that's causing my message box script not to work. Here's the code:

Code:
Sub Message()
MsgBox("Here is your messaage",vbCritical,"Message")
End Sub

This results in a "Compile Error", "Expected: ="

Why is this? And how can I fix it?

Thank you in advance.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You usually only use parentheses when setting the Message Box equal to a variable.
So try it without them, i.e.:L
Code:
Sub Message()
    MsgBox "Here is your messaage", vbCritical, "Message"
End Sub
 
Upvote 0
You need to create a variable which will store the MsgBox. Try this:

Code:
Sub Message()
Dim Answer as String
Answer = MsgBox("Here is your message",vbCritical,Title:="Message")
End Sub
 
Upvote 0
You need to create a variable which will store the MsgBox.
You CAN, but you don't really NEED to. It all depends upon your needs and what you plan do it with it.
If you are just returning a value back to the screen, it is not necessary. If you want to save it for little, or add or modify it, then you probably would want to store it as a variable.
 
Upvote 0
You usually only use parentheses when setting the Message Box equal to a variable.
So try it without them, i.e.:L
Code:
Sub Message()
    MsgBox "Here is your message", vbCritical, "Message"
End Sub

No parens makes it work. Thank you for your help, all.
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top