Consulting

Results 1 to 14 of 14

Thread: VBA code that Unhides sheets that are hidden using sht.Visible = xlSheetVeryHidden

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    VBA code that Unhides sheets that are hidden using sht.Visible = xlSheetVeryHidden

    I have hidden some worksheets using xlSheetVeryHidden. Now when I try to unhide a specific sheet, and selecting it, but it keeps giving me a subscript out of range error.
    How can I unhide the worksheet.

    I've tried
    Worksheets("Home-Page").Select
    Worksheets("Home-Page").Visible = True
    Worksheets("Home-Page").xlSheetVeryHidden = False
    Worksheets("Home-Page").unhide = True

  2. #2
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Now I'm getting a diffrent error:
    Unable to set visible property of the worksheet class

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    WorkSheets("Home-Page").Visible = [One of the below]
    xlSheetHidden
    xlSheetVisible
    xlSheetVeryHidden


    In the VBA Editor, place the cursor inside or next to the word "Visible" and press F1 for help on the Visible Property.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Your second line should work:
    Worksheets("Home-Page").Visible = True
    (substitute xlSheetVisible for True if it's being picky),
    but if you get a subscript out of range error then you've got the name of the sheet wrong.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks for the ideas, code and suggestions.
    I did use a crude solution, after all of the suggested ones did not work.

    On this one: Worksheets("Home-Page").Visible = xlSheetVisible I checked and xlSheetVisible had a value of -1

    What I finally did was to Unhide ALL of the worksheets, and then individually hid them one at a time except for the Home-Page.
    This works, however, I now get a Subscript out of range error when I start the workbook.
    I've checked WorkBook open and Before Close code. No luck finding anything that remotely looks like it changed.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Please attach an empty workbook based on your current workbook settings? Are you sure the name of the sheet is correct?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Aussiebear : I would normally do that, but this workbook is way too huge.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe try

    ThisWorkbook.Worksheets("Home-Page").Visible = xlSheetVisible
    For Each ws In ThisWorkbook.Worksheets
    
        If ws.Name <> "Home-Page" Then
    
            ws.Visible = xlSheetVeryHidden
        End If
    Next ws
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks xld

    I did the equivalent to that in the crude way that I described earlier. The home page is available etc..etc...
    Is there a way to force the editor to show me where the error is located, i.e. & in which module.
    The error Run-time error '9' Subscript out of range does not give me the option to Debug. Only End or Help
    It appears at startup.
    I'm hoping there's a Utility or something that is available.

  10. #10
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks to Everyone who contributed.
    I found that this was causing the error.

    Application.WindowState = xlMaximized   
          If Worksheets("Home-Page").Visible = False Then
                Worksheets("Home-Page").Visible = xlSheetVisible
          End If
    It worked for years earlier, and It was the only part of the code in that Workbook Open Sub.

    The workaround was to include On Error Resume Next.
    Hate having to do that, but ! !

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Quote Originally Posted by simora View Post
    Aussiebear : I would normally do that, but this workbook is way too huge.
    Really, an empty workbook with just the current workbook settings is too large for here? I'm confident you could manage this, including the code you are using to set or adjust the sheet visible properties.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Hi Aussiebear :
    I almost always try to include a workbook but I felt that because so many of the sheets had related links etc...etc. that the only way to track down the problem was to have access to the whole workbook. All 30+ sheets.
    The solution to unhide all the worksheets allowed to to see that was in fact the case. I needed to look at all the worksheets.
    Had I designed this myself, I would've done things entirely different. Multiple people adding stuff over the years causes these type of issues.
    Thanks for all your suggestions & solutions.

  13. #13
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Okay, but we are simply trying to second guess what's at your end of the monitor.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  14. #14
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Aussiebear: Trust me, I do understand.

    & Thanks.

Posting Permissions

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