+ Reply to Thread
Results 1 to 3 of 3

Message Box

  1. #1
    Jordan
    Guest

    Message Box

    I have a macro that clears cells. I would like to ask the user if they are
    sure they want to complete the macro before it runs. Can any one tell me how
    to get the message box to appear with a yes or no button and also if they say
    no how to stop the macro from running.

    I only know how to write macro by recording them so the more information you
    can give me will be greatly appreciated.

    Thanks.

  2. #2
    Richard
    Guest

    RE: Message Box

    Dim stMsg, stTitle As String
    Dim iResponse, iStyle As Integer

    ' Define message.
    stMsg = "Are you sure?"
    ' Define buttons.
    iStyle = vbYesNo + vbQuestion
    ' Define title.
    stTitle = "Title of MsgBox"

    ' Display message.
    iResponse = MsgBox(stMsg, iStyle, stTitle)

    iRespose will have an integer: either vbYes or vbNo based on what user
    selects.

    So you can use like this:

    if iResponse = vbYes Then ' use clicked yes
    Do something
    else ' user clicked no
    do something else
    end if

    "Jordan" wrote:

    > I have a macro that clears cells. I would like to ask the user if they are
    > sure they want to complete the macro before it runs. Can any one tell me how
    > to get the message box to appear with a yes or no button and also if they say
    > no how to stop the macro from running.
    >
    > I only know how to write macro by recording them so the more information you
    > can give me will be greatly appreciated.
    >
    > Thanks.


  3. #3
    Richard
    Guest

    RE: Message Box

    sorry use exit sub to exit the sub immediately and stop the rest of the macro
    from executing.

    "Richard" wrote:

    > Dim stMsg, stTitle As String
    > Dim iResponse, iStyle As Integer
    >
    > ' Define message.
    > stMsg = "Are you sure?"
    > ' Define buttons.
    > iStyle = vbYesNo + vbQuestion
    > ' Define title.
    > stTitle = "Title of MsgBox"
    >
    > ' Display message.
    > iResponse = MsgBox(stMsg, iStyle, stTitle)
    >
    > iRespose will have an integer: either vbYes or vbNo based on what user
    > selects.
    >
    > So you can use like this:
    >
    > if iResponse = vbYes Then ' use clicked yes
    > Do something
    > else ' user clicked no
    > do something else
    > end if
    >
    > "Jordan" wrote:
    >
    > > I have a macro that clears cells. I would like to ask the user if they are
    > > sure they want to complete the macro before it runs. Can any one tell me how
    > > to get the message box to appear with a yes or no button and also if they say
    > > no how to stop the macro from running.
    > >
    > > I only know how to write macro by recording them so the more information you
    > > can give me will be greatly appreciated.
    > >
    > > Thanks.


+ 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