Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Changing the name of a message box

Can I change the name of a messege box to something other than Microsoft Excel?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

This is where referring to the Help files helps (put cursor in or next to
the MsgBox keyword and press F1)... it explains what the optional arguments
mean. You want to assign something to the Title argument...

MsgBox "HI", Title:="This is my title"

--
Rick (MVP - Excel)


"Bishop" wrote in message
...
Can I change the name of a messege box to something other than Microsoft
Excel?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

Remove the parentheses... while they will work if the MsgBox command is
called as a subroutine (rather than if it is called as a function) if only
one argument is specified, using the parentheses with more than one argument
(again, when called as a subroutine) will always generate an error. For
subroutine calls, there are only two reliable methods, either this way...

Command Arg1, Arg2, etc

or this way...

Call Command(Arg1, Arg2, etc)

You can use the parentheses only with the second calling method. So, you
need to do your call either this way....

MsgBox "Fill in this information before continuing.", , "WARNING!"

or this way...

Call MsgBox("Fill in this information before continuing.", , "WARNING!")

Note - You do not need to specify trailing commas if there no additional
optional arguments following them.

--
Rick (MVP - Excel)


"Bishop" wrote in message
...
Apparently I'm not understanding the syntax involved. I totally see what
you're talking about but the help file example isn't very helpful. This
is
what I've tried:
MsgBox ("You have to fill in this information before you can
continue.",,"WARNING!",,)
I've tried every combination with and without , placeholders. I've tried
using no quotes. And I either get a "= expected" error or an "expression"
error.

The syntax required in the helpfile is: MsgBox(prompt[, buttons] [, title]
[, helpfile, context])

So why doesn't this work?


"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever you use
as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

Just to be clear, you are using MsgBox as a subroutine in Method 1 and as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when used
as a subroutine, they are only mandatory when the Call keyword is used and a
mistake to use otherwise. Here is the reason why as I explained it in an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however, when the
Call keyword is omitted, the parentheses are syntactically incorrect. So you
are probably asking, "Why did it work when I didn't add the 2nd argument?"
Good question. It seems that when parentheses are used in a statement that
are not required by syntax, VB assumes it has an expression to evaluate and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Changing the name of a message box

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when used
as a subroutine, they are only mandatory when the Call keyword is used and a
mistake to use otherwise. Here is the reason why as I explained it in an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however, when the
Call keyword is omitted, the parentheses are syntactically incorrect. So you
are probably asking, "Why did it work when I didn't add the 2nd argument?"
Good question. It seems that when parentheses are used in a statement that
are not required by syntax, VB assumes it has an expression to evaluate and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Changing the name of a message box

Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?", buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when used
as a subroutine, they are only mandatory when the Call keyword is used and a
mistake to use otherwise. Here is the reason why as I explained it in an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however, when the
Call keyword is omitted, the parentheses are syntactically incorrect. So you
are probably asking, "Why did it work when I didn't add the 2nd argument?"
Good question. It seems that when parentheses are used in a statement that
are not required by syntax, VB assumes it has an expression to evaluate and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?




--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and
as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when
used
as a subroutine, they are only mandatory when the Call keyword is used
and a
mistake to use otherwise. Here is the reason why as I explained it in
an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a statement
that
are not required by syntax, VB assumes it has an expression to evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated
an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?



--

Dave Peterson


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Changing the name of a message box

But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and
as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when
used
as a subroutine, they are only mandatory when the Call keyword is used
and a
mistake to use otherwise. Here is the reason why as I explained it in
an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a statement
that
are not required by syntax, VB assumes it has an expression to evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated
an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?



--

Dave Peterson



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Changing the name of a message box

Msgbox "thanks!"

(no need to ask if you meant it <vbg.)

Rick Rothstein wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and
as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when
used
as a subroutine, they are only mandatory when the Call keyword is used
and a
mistake to use otherwise. Here is the reason why as I explained it in
an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a statement
that
are not required by syntax, VB assumes it has an expression to evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated
an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?



--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

Oh, I see what you mean... I used vbYesNo as part of the MsgBox example in
my caution. When you said "informational", you meant when called as a
subroutine... for that usage, you are right, there would be no need for
anything but the default OK button because there will be no code examining
the response. My caution about the parentheses still applies though (you
just wouldn't be modifying the number of buttons when specifying multiple
arguments). My example should have been something like this instead...

MsgBox "Doing that may cause a problem!", vbExclamation"

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog.
<g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1
and
as a
function in Method 2 (you are testing a value that is returned from
the
MsgBox call)... when used as a function, parentheses are required,
when
used
as a subroutine, they are only mandatory when the Call keyword is
used
and a
mistake to use otherwise. Here is the reason why as I explained it
in
an old
posting of mine...

As others have shown without specifically pointing to the reason,
your
problem stems from the parentheses. MsgBox is a function and when
used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the
function
effectively becomes a subroutine. There are two proper ways to call
a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically
incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a
statement
that
are not required by syntax, VB assumes it has an expression to
evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When
you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some
kind
between them (the comma is not an expression operator), so it
generated
an
error. The bottom line is to use parentheses in a subroutine
statement
**only** when they are required by syntax (do not use them to
"pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically,
whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other
than
Microsoft Excel?



--

Dave Peterson






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Changing the name of a message box

Every once in awhile, I'll see someone use Call with functions built into
excel's VBA. I find it confusing and distracting (but I'm easily confused and
distracted).

The same goes for seeing code like:
mystr = VBA.Trim(mystr)

If they use it for trim, then they should use it for all.



JLGWhiz wrote:

But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and
as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when
used
as a subroutine, they are only mandatory when the Call keyword is used
and a
mistake to use otherwise. Here is the reason why as I explained it in
an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a statement
that
are not required by syntax, VB assumes it has an expression to evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated
an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?



--

Dave Peterson




--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Changing the name of a message box

Right, when it does nothing but deliver a message, it is informational.
When it returns a value to a variable it is functional. So, if you do not
expect a response from the user, the there is no need for a Yes, No or
Cancel, or Question option. The Information, Exclamation and Critical could
still be cogent options. The OK button will show up if no other button is
specified.


"Rick Rothstein" wrote in message
...
Oh, I see what you mean... I used vbYesNo as part of the MsgBox example in
my caution. When you said "informational", you meant when called as a
subroutine... for that usage, you are right, there would be no need for
anything but the default OK button because there will be no code examining
the response. My caution about the parentheses still applies though (you
just wouldn't be modifying the number of buttons when specifying multiple
arguments). My example should have been something like this instead...

MsgBox "Doing that may cause a problem!", vbExclamation"

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog.
<g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1
and
as a
function in Method 2 (you are testing a value that is returned from
the
MsgBox call)... when used as a function, parentheses are required,
when
used
as a subroutine, they are only mandatory when the Call keyword is
used
and a
mistake to use otherwise. Here is the reason why as I explained it
in
an old
posting of mine...

As others have shown without specifically pointing to the reason,
your
problem stems from the parentheses. MsgBox is a function and when
used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the
function
effectively becomes a subroutine. There are two proper ways to call
a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically
incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a
statement
that
are not required by syntax, VB assumes it has an expression to
evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When
you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has
no
mechanism to evaluate two expressions without an operator of some
kind
between them (the comma is not an expression operator), so it
generated
an
error. The bottom line is to use parentheses in a subroutine
statement
**only** when they are required by syntax (do not use them to
"pretty"
things up as doing that will create problems in more situations
than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically,
whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other
than
Microsoft Excel?



--

Dave Peterson





  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

For those reading this thread, I just want to make it clear that, while
directed toward the MsgBox, my comments about the use of parentheses with
subroutines are fully applicable to subroutines in general, not just when
the MsgBox is used as a subroutine.

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
Right, when it does nothing but deliver a message, it is informational.
When it returns a value to a variable it is functional. So, if you do not
expect a response from the user, the there is no need for a Yes, No or
Cancel, or Question option. The Information, Exclamation and Critical
could still be cogent options. The OK button will show up if no other
button is specified.


"Rick Rothstein" wrote in message
...
Oh, I see what you mean... I used vbYesNo as part of the MsgBox example
in my caution. When you said "informational", you meant when called as a
subroutine... for that usage, you are right, there would be no need for
anything but the default OK button because there will be no code
examining the response. My caution about the parentheses still applies
though (you just wouldn't be modifying the number of buttons when
specifying multiple arguments). My example should have been something
like this instead...

MsgBox "Doing that may cause a problem!", vbExclamation"

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog.
<g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1
and
as a
function in Method 2 (you are testing a value that is returned
from the
MsgBox call)... when used as a function, parentheses are required,
when
used
as a subroutine, they are only mandatory when the Call keyword is
used
and a
mistake to use otherwise. Here is the reason why as I explained it
in
an old
posting of mine...

As others have shown without specifically pointing to the reason,
your
problem stems from the parentheses. MsgBox is a function and when
used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the
function
effectively becomes a subroutine. There are two proper ways to
call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required;
however,
when the
Call keyword is omitted, the parentheses are syntactically
incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a
statement
that
are not required by syntax, VB assumes it has an expression to
evaluate
and,
well, it attempts to evaluate the contents of the parentheses.
When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has
no
mechanism to evaluate two expressions without an operator of some
kind
between them (the comma is not an expression operator), so it
generated
an
error. The bottom line is to use parentheses in a subroutine
statement
**only** when they are required by syntax (do not use them to
"pretty"
things up as doing that will create problems in more situations
than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote
in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically,
whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other
than
Microsoft Excel?



--

Dave Peterson






  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the name of a message box

The Information, Exclamation and Critical could still be cogent options.

Including the Title is another way to have two (or more) arguments in a
MsgBox, so the proper use of parentheses should still be observed.

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
Right, when it does nothing but deliver a message, it is informational.
When it returns a value to a variable it is functional. So, if you do not
expect a response from the user, the there is no need for a Yes, No or
Cancel, or Question option. The Information, Exclamation and Critical
could still be cogent options. The OK button will show up if no other
button is specified.


"Rick Rothstein" wrote in message
...
Oh, I see what you mean... I used vbYesNo as part of the MsgBox example
in my caution. When you said "informational", you meant when called as a
subroutine... for that usage, you are right, there would be no need for
anything but the default OK button because there will be no code
examining the response. My caution about the parentheses still applies
though (you just wouldn't be modifying the number of buttons when
specifying multiple arguments). My example should have been something
like this instead...

MsgBox "Doing that may cause a problem!", vbExclamation"

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog.
<g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1
and
as a
function in Method 2 (you are testing a value that is returned
from the
MsgBox call)... when used as a function, parentheses are required,
when
used
as a subroutine, they are only mandatory when the Call keyword is
used
and a
mistake to use otherwise. Here is the reason why as I explained it
in
an old
posting of mine...

As others have shown without specifically pointing to the reason,
your
problem stems from the parentheses. MsgBox is a function and when
used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the
function
effectively becomes a subroutine. There are two proper ways to
call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required;
however,
when the
Call keyword is omitted, the parentheses are syntactically
incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a
statement
that
are not required by syntax, VB assumes it has an expression to
evaluate
and,
well, it attempts to evaluate the contents of the parentheses.
When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has
no
mechanism to evaluate two expressions without an operator of some
kind
between them (the comma is not an expression operator), so it
generated
an
error. The bottom line is to use parentheses in a subroutine
statement
**only** when they are required by syntax (do not use them to
"pretty"
things up as doing that will create problems in more situations
than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote
in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically,
whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other
than
Microsoft Excel?



--

Dave Peterson






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the name of a message box Patrick Molloy[_2_] Excel Programming 3 April 17th 09 07:14 PM
Changing the name of a message box Dave Peterson Excel Programming 0 April 17th 09 06:28 PM
Changing a message box colour? Simon Lloyd[_658_] Excel Programming 2 October 23rd 05 06:52 AM
changing the message in an error message The Villages DA Excel Worksheet Functions 2 February 18th 05 05:30 PM
changing font in message box shaharul[_4_] Excel Programming 1 September 17th 03 03:47 AM


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"