+ Reply to Thread
Results 1 to 3 of 3

Cannot set worksheet visibility in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2009
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    3

    Cannot set worksheet visibility in VBA

    In VBA, 'ThisWorkbook' contains code that should open a Welcome page with instructions for enabling macros if the user does not have macros enabled. Once enabled, the worksheet titled 'Calculator' should display. It was working as desired until I added the worksheet titled 'KB'.

    I tried to go to properties in VBA for 'KB' and set Visible to xlSheetHidden and get an error message that Excel cannot set the visibility.

    Thinking the 'ThisWorkbook' code was forcing it to display, I tried to add code to hide 'KB'. Nothing worked. I believe I undid all my changes but now when I open the workbook, the Welcome worksheet flashes, immediately disappears and the active worksheet is 'KB'.

    Any ideas on how to restore the original function and successfully hide 'KB'? Note: the coding is not very elegant, I'm sure. I just started trying to learn VBA 4 days ago.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Cannot set worksheet visibility in VBA

    The only problem I could see is you are unhiding KB when you Unhide all sheets.

    Add this...
    Private Sub ShowAllSheets()
         'Show all worksheets except the macro welcome page
         
        Dim ws As Worksheet
          
        For Each ws In ThisWorkbook.Worksheets
            If Not ws.Name = WelcomePage And ws.Name <> "KB" Then ws.Visible = xlSheetVisible
        Next ws
        Worksheets(WelcomePage).Visible = xlSheetVeryHidden
    End Sub
    One other suggestion is to add a button on the Welcome page so the user could click it to hide Welcome and unhide Calculator after they have changed their security setting.

  3. #3
    Registered User
    Join Date
    09-28-2009
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Cannot set worksheet visibility in VBA

    Thank you so very much! This worked like a charm and I now understand where I was going wrong in trying to compile that code. I appreciate you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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