Message Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to add a message box into a macro that will provide Yes / No
option. "Yes " to continue macro and "No" to end macro.
 
One way:

Dim nResult As Long
nResult = Msgbox(Prompt:="Continue?", Buttons:=vbYesNo)
If nResult = vbYes Then
'Your code here
End If

Or, if you don't mind having multiple exit points to your macro:

Dim nResult As Long
nResult = Msgbox(Prompt:="Continue?", Buttons:=vbYesNo)
If nResult = vbNo then Exit Sub
'Your code here
 
Dim Resp as long

......

Resp = msgbox(Prompt:="Want to continue?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

.....
 
Ron,

If you won't be testing the yes/no response anywhere else, then you can shorten the code to:

If MsgBox("Continue?", vbYesNo, "Please answer this short question.") = vbYes Then
' Yes code goes here
MsgBox "Yes"
Else
' No code goes here
End
End If

--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Thank you your info has helped me and saved me heaps of time. I had been
trying to achieve this for last two days. Very much appreciated.
 
From the 3 replies I received yours was the one that was simplest for me to
follow and have used it. thankyou very much.

I would like to rate your response but can not see how I do this. Top Marks
from me.
 
Thankyou for your response. You have given me an additional option which will
help me on another project. Your quick response is very much apptreciated.
 
In a couple of hours/days/weeks..., you'll be able to look back and read each
response and see that they're pretty much equivalent.

It never hurts me (too much) to revisit things when I get a little smarter <bg>.
 
Dave, What does this <bg> tag mean?

Dave Peterson said:
In a couple of hours/days/weeks..., you'll be able to look back and read each
response and see that they're pretty much equivalent.

It never hurts me (too much) to revisit things when I get a little smarter <bg>.
 
Back
Top