Thread: msgBox
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
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!!!!