#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default 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
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
Message Box Ron (Bismark) Excel Discussion (Misc queries) 11 September 4th 07 04:06 AM
Opening an attachment of a message that has a message as attachmen vetron Excel Programming 0 January 30th 06 06:17 PM
changing the message in an error message The Villages DA Excel Worksheet Functions 2 February 18th 05 05:30 PM
What does this message mean? Lulu[_2_] Excel Programming 1 August 19th 04 08:22 PM
Displaying a message in a message box without requiring user to click anything to proceed Android[_2_] Excel Programming 2 June 25th 04 06:44 PM


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