Setting caption for a messagebox

P

Peter

Hello,

How can I modify this code to set a caption in my message box, I seem to get
a compile error every time I try:
MsgBox(prompt:=strOption1, Buttons:=vbYesNo)

strOption1 is a string varible that has been pre defined.


Thanks,
Peter
 
J

Jay Freedman

Hello,

How can I modify this code to set a caption in my message box, I seem to get
a compile error every time I try:
MsgBox(prompt:=strOption1, Buttons:=vbYesNo)

strOption1 is a string varible that has been pre defined.


Thanks,
Peter

I think your problem is not with the prompt, rather that you're using
parentheses around the parameters but you aren't assigning the
function result to anything. Try writing

nResult = MsgBox(prompt:=strOption1, Buttons:=vbYesNo)

where nResult is declared as an Integer. Alternatively, you can
implicitly use the function result in a logical statement:

If MsgBox(prompt:=strOption1, Buttons:=vbYesNo) = vbYes Then
' ...
End If

When you use MsgBox as a subroutine (not returning a value), then you
must omit the parentheses:

MsgBox prompt:="This is my message"

See http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm
for an explanation.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
P

Peter

Hi Jay,

I am now using :

Response = MsgBox(prompt:=strOption1, Buttons:=vbYesNo)

How do I get the title in the title bar of the message box to display
something other than the default (Word).

Thanks,
Peter
 
C

Charles Kenyon

Set the Title property as well.
, Title:="This is my message box. Please read!"
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
P

Peter

Thanks Charles,

That Worked!

Charles Kenyon said:
Set the Title property as well.
, Title:="This is my message box. Please read!"
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top