Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Message Box | Excel Discussion (Misc queries) | |||
Opening an attachment of a message that has a message as attachmen | Excel Programming | |||
changing the message in an error message | Excel Worksheet Functions | |||
What does this message mean? | Excel Programming | |||
Displaying a message in a message box without requiring user to click anything to proceed | Excel Programming |