Can't get Cancel to work in message box

G

Guest

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

------------------------------------------------------------------------------------------------
 
D

Dave O

You could change the line that currently says
Cancel = True
to this:
End

....which will stop the macro.
 

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