Exiting Sub when Selecting Cancel on vbOKCancel

G

Guest

Hi Again,

How would I make it to where if I select cancel from this msxbox...

MsgBox "Do You Want to Run the Activation/De-Activation Code Checker?",
vbOKCancel

....it exits the sub and does not perform anything else within the sub?
Right now if I select cancel it still finishes the sub. Any help would be
great.

Thanks Much,
Rob
 
D

Dave Peterson

Dim Resp as long
resp = msgbox(Prompt:="do you want...", buttons:=vbokcancel)
if resp = vbcancel then
exit sub
end if
'keep going
 
D

Dave O

Rob-
As written your code pops up a message box with a prompt for the user,
and nothing happens when you click Cancel because there is no code to
accommodate any activity. By declaring a variable to hold the user's
answer, you can then act on it- try adding code like this:

Dim Response As String 'variable to hold user's answer
Response = MsgBox("Do You Want to Run the Activation/De-Activation
Code Checker?", vbOKCancel)
If Response = vbCancel Then
End
End If

You may want to use a vbYesNo instead of vbOKCancel, since that is a
slightly more intuitive answer to your "do you want to run this"
question.

Dave O
 
D

Dave O

Rob-
As written your code pops up a message box with a prompt for the user,
and nothing happens when you click Cancel because there is no code to
accommodate any activity. By declaring a variable to hold the user's
answer, you can then act on it- try adding code like this:

Dim Response As String 'variable to hold user's answer
Response = MsgBox("Do You Want to Run the Activation/De-Activation
Code Checker?", vbOKCancel)
If Response = vbCancel Then
End
End If

You may want to use a vbYesNo instead of vbOKCancel, since that is a
slightly more intuitive answer to your "do you want to run this"
question.

Dave O
 
D

Dave O

Rob-
As written your code pops up a message box with a prompt for the user,
and nothing happens when you click Cancel because there is no code to
accommodate any activity. By declaring a variable to hold the user's
answer, you can then act on it- try adding code like this:

Dim Response As String 'variable to hold user's answer
Response = MsgBox("Do You Want to Run the Activation/De-Activation
Code Checker?", vbOKCancel)
If Response = vbCancel Then
End
End If

You may want to use a vbYesNo instead of vbOKCancel, since that is a
slightly more intuitive answer to your "do you want to run this"
question.

Dave O
 
D

Dave O

Rob-
As written your code pops up a message box with a prompt for the user,
and nothing happens when you click Cancel because there is no code to
accommodate any activity. By declaring a variable to hold the user's
answer, you can then act on it- try adding code like this:

Dim Response As String 'variable to hold user's answer
Response = MsgBox("Do You Want to Run the Activation/De-Activation
Code Checker?", vbOKCancel)
If Response = vbCancel Then
End
End If

You may want to use a vbYesNo instead of vbOKCancel, since that is a
slightly more intuitive answer to your "do you want to run this"
question.

Dave O
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top