#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default msgBox

I have a problem with my help menue so please dont just refer to it. i want
to have a messagebox that pops up when the user presses a button. the message
box shall ask the user if he(she is sure if he wants to abort. i just dont
get the syntax. I know to write the text on the box but how to choose how
many and what type of buttons etc. i dont know. i dont know how to connect an
event to certain button in the message box. please help me on this one!!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default msgBox

Message boxes return values (of type long integer). Luckily you do not need
to remember all of the integers as there are preset aliases for the values
returned such as vbYes, vbNo and vbCancel. So for the simplest message boxes
you can use a statement such as this

if msgbox("Would you like to continue?", vbYesNo, "Continue") = vbYes then
'Do your stuff
end if

Note that the first itme in the Bracets is the Text of the message, The
second item is the button type an the third item is the title. You can get a
bit more elaborate with the button type by using the + sysmbol. Try the code
below. Note that the message box is an information box with buttons
abort/retry/ignore and that the 3rd button is the default reply... I used a
variable to hold the value of the message box since there are 3 possible
answers

Sub test()
Dim lngResponse As Long

lngResponse = MsgBox("What do you want to do?", _
vbDefaultButton3 + vbInformation + vbAbortRetryIgnore, _
"What to Do?")
If lngResponse = vbIgnore Then
MsgBox "Pressed Ignore"
ElseIf lngResponse = vbRetry Then
MsgBox "Pressed Retry"
Else
MsgBox "Pressed Abort"
End If
End Sub
--
HTH...

Jim Thomlinson


"april27" wrote:

I have a problem with my help menue so please dont just refer to it. i want
to have a messagebox that pops up when the user presses a button. the message
box shall ask the user if he(she is sure if he wants to abort. i just dont
get the syntax. I know to write the text on the box but how to choose how
many and what type of buttons etc. i dont know. i dont know how to connect an
event to certain button in the message box. please help me on this one!!!!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default msgBox

I think you want something like this:

If MsgBox("Do you want to abort this macro?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"aborting macro") = vbYes Then
Exit Sub
End If

RBS

"april27" wrote in message
...
I have a problem with my help menue so please dont just refer to it. i want
to have a messagebox that pops up when the user presses a button. the
message
box shall ask the user if he(she is sure if he wants to abort. i just dont
get the syntax. I know to write the text on the box but how to choose how
many and what type of buttons etc. i dont know. i dont know how to connect
an
event to certain button in the message box. please help me on this one!!!!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default msgBox

Hi April27,

I have a problem with my help menue so please dont just refer to it. i want
to have a messagebox that pops up when the user presses a button. the message
box shall ask the user if he(she is sure if he wants to abort. i just dont
get the syntax. I know to write the text on the box but how to choose how
many and what type of buttons etc. i dont know. i dont know how to connect an
event to certain button in the message box. please help me on this one!!!!



Sub MsgBoxDemo()
Select Case MsgBox("What do you want to do?" _
, vbAbortRetryIgnore + vbQuestion, "MsgBoxDemo")
Case vbAbort
MsgBox "Abort!", vbCritical
Case vbRetry
MsgBox "Retry!", vbExclamation
Case vbIgnore
MsgBox "Ignore", vbInformation
End Select

End Sub


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

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
msgbox in VBA peyman Excel Discussion (Misc queries) 6 October 6th 07 09:35 PM
msgbox peyman Excel Discussion (Misc queries) 5 October 4th 07 09:56 PM
msgbox ceemo[_40_] Excel Programming 3 October 29th 05 07:20 PM
help with msgbox shirley Excel Programming 3 February 10th 04 04:58 AM
Msgbox serge Excel Programming 1 January 28th 04 01:48 PM


All times are GMT +1. The time now is 11:33 PM.

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"