Correct syntax for msgbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
With the sytax below i keep getting a error.
It did have vbInformation but i removed it & now error is shown.
Whats the correct way for text,OK button & message title.



Rich (BB code):
 MsgBox "CONTINUE TO NOW HYPERLINK CUSTOMER & PHOTO ?", "HYPERLINK PHOTO MESSAGE"
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You are missing the "Buttons" argument between the "Prompt" and "Title".
See: MsgBox function (Visual Basic for Applications)
(note: ALL these VBA functions are documented on-line and can be found with a simple Google search).

Since it is an optional argument, just add another comma to account for it, i.e.
VBA Code:
 MsgBox "CONTINUE TO NOW HYPERLINK CUSTOMER & PHOTO ?",,"HYPERLINK PHOTO MESSAGE"
 
Upvote 0
Solution
Did a google search but didnt spot part about the comma

Now working thanks
 
Upvote 0
Did a google search but didnt spot part about the comma

Now working thanks
You are welcome.

It is just a matter of understanding what the various different arguments for the function are. The have to appear in the designated order, and are separated by commas. So if you have an "optional" argument, you can just leave it blank by having nothing between those two commas.

So in the link I provided you, it shows the arguments needed and their order:

1701277215622.png

As you can see, the first argument is "prompt" and it is required.
The "title" argument is the third and is optional.
So if you want to include both "prompt" and "title", you need to have at least 3 arguments, which means you need to have a value for the 2nd argument as well.
The second argument, "buttons", is also optional. So you can just leave it blank.

So in your case:
VBA Code:
MsgBox prompt, buttons, title
can just be written like:
VBA Code:
MsgBox prompt,,title

Since button is optional, you don't need a value for it, but you still need the comma as the placeholder so the "title" is still the 3rd argument.
Make sense?
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,300
Members
449,095
Latest member
Chestertim

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