ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Message Box (https://www.excelbanter.com/excel-programming/355061-message-box.html)

Jordan

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.

Richard

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.


Richard

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.



All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com