Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default vbOKCancel box to close

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default vbOKCancel box to close

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)

wrote in message
ps.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default vbOKCancel box to close

You need to check the return value from MsgBox()

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

End Sub

NickHK

wrote in message
ps.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default vbOKCancel box to close

Thanks Guys,

Worked a treat.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing vbOKCancel button title Jase Excel Discussion (Misc queries) 8 August 19th 08 08:56 PM
Exiting Sub when Selecting Cancel on vbOKCancel Rob Excel Discussion (Misc queries) 6 June 1st 07 03:46 AM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM
Qn: vbOKCancel -- Cancel doesn't work?? Michael Vaughan Excel Programming 4 August 27th 04 07:31 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"