ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Can't get Cancel to work in message box (https://www.excelbanter.com/excel-discussion-misc-queries/80612-cant-get-cancel-work-message-box.html)

* Kenneth *

Can't get Cancel to work in message box
 
I having problems with getting the cancel to cancel or close the massage box
at any time the macro is running.

Help

-----------------------------------------------------------------------------------------------

Sub HideYesNo()

Dim iYesNo As Integer
Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

For Each ws In wb.Worksheets
If Sheets(ws.Name).Visible Then
iYesNo = MsgBox("Hide Sheet " & ws.Name & _
" ?", vbQuestion + vbYesNoCancel, _
"Hide This Sheet")
If iYesNo = vbCancel Then
Cancel = True
If iYesNo = vbYes Then
Sheets(ws.Name).Visible = False
End If
End If
End If
Next ws

Set wb = Nothing
Set ws = Nothing

------------------------------------------------------------------------------------------------

Dave O

Can't get Cancel to work in message box
 
You could change the line that currently says
Cancel = True
to this:
End

....which will stop the macro.



All times are GMT +1. The time now is 11:07 PM.

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