Consulting

Results 1 to 4 of 4

Thread: Solved: Hide worksheets file close

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    44
    Location

    Solved: Hide worksheets file close

    Evening all,

    The attached workbook is designed for multiple users who have to enter a username and specific password to access their assigned worksheet(s). The problem I'm currently faced with is that once the file has been saved and closed, those worksheets that have been unloaded are still visible.

    What I am attempting to do is hide all visible worksheets bar one (ImportantInformation) on file close. Unfortunately for some reason I can't quite get the command to function whatsoever.

    I've tried multiple variations using Workbook Before Close, to no avail. Any help would be much appreciated.

    FYI the usernames and passwords for each worksheet can be found in L2:N10 on the ImportantInformation worksheet.

    Thanks in advance.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Check the kbase there's a brilliant example there!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    Change you Workbook_BeforeClose event to:

    [vba]Sub Workbook_BeforeClose(Cancel As Boolean)

    ThisWorkbook.Unprotect Password:="Password"
    Dim wSht As Worksheet
    Application.ScreenUpdating = False
    For Each wSht In Worksheets
    If wSht.Name <> "ImportantInformation" Then
    wSht.Visible = xlVeryHidden

    End If
    Next
    Application.ScreenUpdating = True
    ThisWorkbook.Protect Password:="Password"

    End Sub[/vba]
    Last edited by mbarron; 12-16-2009 at 01:33 PM.

  4. #4
    VBAX Regular
    Joined
    Aug 2009
    Posts
    44
    Location
    Simon, thanks for the heads up.

    mbarron, thank you, the modified code you supplied worked a treat - much appreciated.

Posting Permissions

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