+ Reply to Thread
Results 1 to 4 of 4

msgBox

  1. #1
    april27
    Guest

    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. #2
    Jim Thomlinson
    Guest

    RE: 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. #3
    RB Smissaert
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #4
    Jan Karel Pieterse
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1