Thread: Msgbox Help
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default Msgbox Help

Mike:

The following format uses simple positional arguments:

MsgBox "Hello world!", _
vbInformation + vbOKOnly, _
"Test Message"

The following format uses named arguments. When using named arguments, you
put a colon followed by an equals sign (":=") between the argument name and
the value. Notice that the Buttons argument allows you to sum a bunch of
values together, one to show an icon, another to say what type of button
combination to use, and other values to specify whether the message box is
modal or not. I normally always include an icon, to visually underscore the
importance of the message to the user. In this case, I used the
vbInformation icon, along with the OK button. The "as" that you see is the
VBA editor telling you what type the argument is; it is not included when
you type in your code. In other words, "Buttons" is the parameter,
"VbMsgBoxStyle" is the type of variable that the argument is, so you can
look up "VbMsgBoxStyle" in the Object Browser to see what the valid values
are (or see the MsgBox topic in Excel Help).

MsgBox Prompt:="Hello world!", _
Buttons:=vbInformation + vbOKOnly, _
Title:="Test Message"

Also, if you are not going to use the return value of a function, you
normally do not enclose the arguments in parentheses. If you enclose the
arguments in parentheses, then a compiler error results (the line of code
should be displayed in red). Use the following example, if you are going to
return the value (to see which button the user pressed, if more than one
button is displayed). In this example, leaving the parentheses out will
also result in a compiler error.

Dim varMsgResult As Variant

varMsgResult = MsgBox("Hello world!", _
vbInformation + vbOKOnly, _
"Test Message")

--
Regards,
Bill Renaud