How can I do this message box?

  • Thread starter Thread starter CarolineHedges
  • Start date Start date
C

CarolineHedges

At the beginning of the my macro I would like a message/prompt box t
appear with a question on it.

if the user ticks/presses yes then the marco continues, if the use
presses/clicks no then the macro stops.

Thanks in advanc
 
Public Sub MboxTest()

Dim mbRes As VbMsgBoxResult

mbRes = MsgBox("Do you want to continue?", vbYesNo, "MsgBox Test")

If mbRes = vbNo Then
Exit Sub
Else
'your code here
End If

End Sub



"CarolineHedges"
 
Sub test()
Dim res As Long

res = MsgBox("Do you want to continue", _
vbYesNo Or vbQuestion, "My Macro")

If Not (res = vbYes) Then
MsgBox "Bye"
Exit Sub
End If

MsgBox "Let's go..."

End Sub

Regards,
Peter T

"CarolineHedges"
 
Here's one way.

Msg = "Your question?" ' Define message.
Style = vbYesNo ' Define buttons.
Title = "Title of message box" ' Define title.
If MsgBox(Msg, Style, Title) = vbNo Then End

MsgBox ("You selected Yes. Your code will continue")



"CarolineHedges"
 
Careful using End in code. End is dangerous as it clears all global
variables/objects. You would be better off with Exit Sub...
 
Back
Top