Thread: Message Box
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Richard Richard is offline
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.