vbOKCancel box to close

L

lafinca47

Hi,

I've put in a vbOKCancel box into my macro and all I want it to do is:

If you select Ok continue with the macro if you select Cancel I want
the macro to finsh, so I have put:

MsgBox strName & " - Is The Latest File - " & varDate, vbOKCancel

If answer = vbCancel Then
Exit Sub
Else
Call OpenMost
End If

However when I step through the macro to see if its working when I
click Cancel it skips over the exit sub command and continues with the
rest of the macro. So at the moment it doesn't matter which button I
press the macro goes all the way through to the end.

Am I missing something simple? can anyone advise?

Many Thanks
 
B

Bob Phillips

If MsgBox(strName & " - Is The Latest File - " & varDate, vbOKCancel) =
vbCancel Then
Exit Sub
End If

Call OpenMost


or

answer = MsgBox(strName & " - Is The Latest File - " & varDate, vbOKCancel)

If answer = vbCancel Then
Exit Sub
Else
Call OpenMost
End If


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
N

NickHK

You need to check the return value from MsgBox()

If Msgbox (....) =vbOK Then
'Do your stuff
End

End Sub

NickHK
 

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