Results 1 to 4 of 4

Activate vbCancel in message box

Threaded View

datafiend Activate vbCancel in message... 09-25-2012, 02:31 AM
Andy Pope Re: Activate vbCancel in... 09-25-2012, 04:05 AM
JosephP Re: Activate vbCancel in... 09-25-2012, 04:15 AM
datafiend Re: Activate vbCancel in... 09-25-2012, 04:41 AM
  1. #1
    Registered User
    Join Date
    09-10-2009
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2013
    Posts
    47

    Activate vbCancel in message box

    Hi there
    I'm using a message box to unhide some sheets in my workbook and want to be able to cancel the command when I have unhidden the ones I want. I'm using the code below and though it seemed to work a few times, it won't do so now. Can anyone tell me how I can correct it?

    Thanks in advance for any help.

    datafiend

    Sub UnhideSomeSheets()
        Dim sSheetName As String
        Dim sMessage As String
        Dim Msgres As VbMsgBoxResult
        Dim wsSheet As Worksheet
    
        For Each wsSheet In ActiveWorkbook.Worksheets
            If wsSheet.Visible = xlSheetHidden Then
                sSheetName = wsSheet.Name
                sMessage = "Unhide the following sheet?" _
                  & vbNewLine & sSheetName
                Msgres = MsgBox(sMessage, vbYesNoCancel)
                If Msgres = vbYes Then wsSheet.Visible = xlSheetVisible
               ElseIf Msgres = vbCancel Then Exit Sub
          
            End If
     
        Next wsSheet
    End Sub
    Last edited by datafiend; 09-25-2012 at 04:46 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1