Cancel Button

M

Matt

I have a Macro with an initial warning in the form of an
OkCancel MsgBox. On 'Ok' I want the macro to continue,
and on 'Cancel' I want it to stop entirely. When 'Cancel'
is pressed the macro does not stop. What am I missing?
Thanks.
 
R

Ron de Bruin

Try this Matt

Sub test()
Dim Answer As String
Answer = MsgBox("Hi", vbOKCancel, "Title")
If Answer = vbOK Then
MsgBox "run the macro"
Else
MsgBox "By"
End If
End Sub
 
B

Bob Phillips

Matt,

Is your code like this

If ans = vbCancel Then
'quit code
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Forgot the first bit

ans = MsgBox ("Hello",vbOKCancel)

then the rest.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top