Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default MsgBox basics

Hi Guys

Please help. I am obviously failing to understand something very basic about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now, was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of 'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default MsgBox basics

Phil
Just delete the brackets ... worked for me
Nick

"Phil C" wrote:

Hi Guys

Please help. I am obviously failing to understand something very basic about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now, was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of 'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default MsgBox basics

Hi Phil

Try running this macro to give you a few ideas.

Sub messageboxetc()
Dim X As String
MsgBox "vbInformation", vbInformation
MsgBox "vbCritical", vbCritical
MsgBox "vbAbortRetryIgnore", vbAbortRetryIgnore
MsgBox "vbExclamation", vbExclamation
MsgBox "vbQuestion", vbQuestion
MsgBox "vbYesNoCancel", vbYesNoCancel

X = MsgBox("Do you want to save the changes to " & ThisWorkbook.Name & "?",
vbYesNoCancel, "Microsoft Excel", "", vbExclamation)
If X = vbYes Then
MsgBox "Yes"
ElseIf X = vbNo Then
MsgBox "No"
ElseIf X = vbCancel Then
MsgBox "Cancel"
End If
End Sub

--

Regards

William

XL2003




"Phil C" wrote in message
...
Hi Guys

Please help. I am obviously failing to understand something very basic
about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now, was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the
Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of
'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default MsgBox basics

Phil take out the (), MsgBox "Your time has expired", vbOKOnly, "Time
expiry notification"

or just MsgBox "Your time has expired", , "Time expiry notification"

and for yes no cancel use something like this

Sub Message_box_test()



Msg = "Put message here"

Title = "Put title here"

Response = MsgBox(Msg, vbYesNoCancel + vbQuestion, Title)



If Response = vbNo Then

'your code if no is clicked here

MsgBox "you clicked no"

Exit Sub ' Quit the macro

End If



If Response = vbCancel Then

'your code if Cancel is clicked here

MsgBox "You clicked cancelled"

Exit Sub ' Quit the macro

End If



'your code if Yes is clicked here

MsgBox "you clicked yes"

End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Phil C" wrote in message
...
Hi Guys

Please help. I am obviously failing to understand something very basic
about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now, was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the
Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of
'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default MsgBox basics

Thanks guys

I thought it would be someting simple, but not exactly obvious from MS help.
I will also try William's macro for my further education..!

Phil





"Paul B" wrote in message
...
Phil take out the (), MsgBox "Your time has expired", vbOKOnly, "Time
expiry notification"

or just MsgBox "Your time has expired", , "Time expiry notification"

and for yes no cancel use something like this

Sub Message_box_test()



Msg = "Put message here"

Title = "Put title here"

Response = MsgBox(Msg, vbYesNoCancel + vbQuestion, Title)



If Response = vbNo Then

'your code if no is clicked here

MsgBox "you clicked no"

Exit Sub ' Quit the macro

End If



If Response = vbCancel Then

'your code if Cancel is clicked here

MsgBox "You clicked cancelled"

Exit Sub ' Quit the macro

End If



'your code if Yes is clicked here

MsgBox "you clicked yes"

End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Phil C" wrote in message
...
Hi Guys

Please help. I am obviously failing to understand something very basic
about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now,

was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the
Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of
'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default MsgBox basics

First, you should use the named constants i.e. vbOKOnly etc., instead of
numeric values as this makes your code more readable.

The problem is:

If you are not interested in what key users clicked, the arguments of the
MsgBox function are NOT included in round brackets. If you have included the
arguments in round brackets, the result is not transparently sunk i.e you
need to assign the result to a variable e.g

resp = MsgBox("Message",vbOkOnly)

or use CALL, e.g

Call MsgBox("Message",vbOkOnly)

Strangely, if you have only a single argument within the round brackets, it
does not matter whether you are using round brackets or not.
"Phil C" wrote:

Hi Guys

Please help. I am obviously failing to understand something very basic about
MsgBox syntax.
I have only previously used this function to give simple messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but, for now, was
just trying to customise the title (caption) of the the message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry notification")

produces a compile error ("expected: =") and I can't make sense of the Help
associated.
I am not including any Help/Context, so have left those options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type of 'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0 instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default MsgBox basics

Strangely, if you have only a single argument within the round
brackets, it
does not matter whether you are using round brackets or not.


It does matter. If you enclose the argument to a Sub in
parentheses, VBA evaluates it to its actual value and passes it
ByVal instead of ByRef.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"AA2e72E" wrote in message
...
First, you should use the named constants i.e. vbOKOnly etc.,
instead of
numeric values as this makes your code more readable.

The problem is:

If you are not interested in what key users clicked, the
arguments of the
MsgBox function are NOT included in round brackets. If you have
included the
arguments in round brackets, the result is not transparently
sunk i.e you
need to assign the result to a variable e.g

resp = MsgBox("Message",vbOkOnly)

or use CALL, e.g

Call MsgBox("Message",vbOkOnly)

Strangely, if you have only a single argument within the round
brackets, it
does not matter whether you are using round brackets or not.
"Phil C" wrote:

Hi Guys

Please help. I am obviously failing to understand something
very basic about
MsgBox syntax.
I have only previously used this function to give simple
messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but,
for now, was
just trying to customise the title (caption) of the the
message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry
notification")

produces a compile error ("expected: =") and I can't make
sense of the Help
associated.
I am not including any Help/Context, so have left those
options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type
of 'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0
instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default MsgBox basics

By "it does not matter" I implied that there is no compile error when MsgBox
has a single argument wrapped in round brackets and its return value is
neither assigned not sunk by CALL.

"Chip Pearson" wrote:

Strangely, if you have only a single argument within the round
brackets, it
does not matter whether you are using round brackets or not.


It does matter. If you enclose the argument to a Sub in
parentheses, VBA evaluates it to its actual value and passes it
ByVal instead of ByRef.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"AA2e72E" wrote in message
...
First, you should use the named constants i.e. vbOKOnly etc.,
instead of
numeric values as this makes your code more readable.

The problem is:

If you are not interested in what key users clicked, the
arguments of the
MsgBox function are NOT included in round brackets. If you have
included the
arguments in round brackets, the result is not transparently
sunk i.e you
need to assign the result to a variable e.g

resp = MsgBox("Message",vbOkOnly)

or use CALL, e.g

Call MsgBox("Message",vbOkOnly)

Strangely, if you have only a single argument within the round
brackets, it
does not matter whether you are using round brackets or not.
"Phil C" wrote:

Hi Guys

Please help. I am obviously failing to understand something
very basic about
MsgBox syntax.
I have only previously used this function to give simple
messages to the
user, and provide a single (default) OK button: E.g.

MsgBox "Your time has expired"

I want to add more buttons in due course (Yes, No, etc) but,
for now, was
just trying to customise the title (caption) of the the
message box:

MsgBox ("Your time has expired",vbOKOnly,"Time expiry
notification")

produces a compile error ("expected: =") and I can't make
sense of the Help
associated.
I am not including any Help/Context, so have left those
options blank

I have tried assigning the message and Title as strings

Dim Msg As String
Dim Title As String
Msg = "Your time has expired"
Title = "Time expiry notification"
MsgBox (Msg, vbOKOnly, Title)

but to no avail..

And
MsgBox (Msg, vbOKOnly, Title, , ,) just produces another type
of 'expected'
compile error

Thanks, Phil

PS. Once I have sorted the syntax, I should be able to use 0
instead of
vbOKOnly, 1 for vbOKCancel, etc. Right?








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
DSUM Basics Midland Excel Discussion (Misc queries) 1 August 26th 09 06:15 PM
basics? n21 New Users to Excel 7 September 21st 06 12:37 PM
VBA form basics Colin Foster[_4_] Excel Programming 1 August 4th 05 05:40 PM
Excel VBA basics Philipp Excel Programming 3 October 11th 04 10:11 AM
Help with the basics. Starting out. beeawwb Excel Programming 2 January 9th 04 12:17 AM


All times are GMT +1. The time now is 03:12 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"