ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check Point in VBA (https://www.excelbanter.com/excel-programming/360965-check-point-vba.html)

Brian Matlack[_72_]

Check Point in VBA
 

Hi!
I would like to have a point in my code that displays a message box
that asks the user if they wish to continue or exit the macro. A simple
"Yes" and "No" button would be ok. This may be a point in the main macro
or a point in one of the subroutines.
1. What would the code look like for stopping the entire macro.
2. What would the code look like to stop the subroutine only.

Thanks for any help or advice!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=540310


Chip Pearson

Check Point in VBA
 
Brian,

The following code will exit the current procedure if the user
clicks Yes.

Dim Res As VbMsgBoxResult
Res = MsgBox("Do you want to continue?", vbYesNo)
If Res = vbNo Then
Exit Sub
End If

The following code will completely terminate VBA if the user
clicks Yes. Note that all public (Global) variables will be reset
to their default values.

Dim Res As VbMsgBoxResult
Res = MsgBox("Do you want to continue?", vbYesNo)
If Res = vbNo Then
End
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Brian Matlack"

wrote in message
news:Brian.Matlack.27jpup_1147187410.7878@excelfor um-nospam.com...

Hi!
I would like to have a point in my code that displays a message
box
that asks the user if they wish to continue or exit the macro.
A simple
"Yes" and "No" button would be ok. This may be a point in the
main macro
or a point in one of the subroutines.
1. What would the code look like for stopping the entire macro.
2. What would the code look like to stop the subroutine only.

Thanks for any help or advice!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile:
http://www.excelforum.com/member.php...fo&userid=3508
View this thread:
http://www.excelforum.com/showthread...hreadid=540310




Brian Matlack[_74_]

Check Point in VBA
 

Thanks Chip!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=540310



All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com