Results 1 to 8 of 8

Show / Hide specific sheets per username

Threaded View

  1. #1
    Registered User
    Join Date
    04-24-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Show / Hide specific sheets per username

    Hi all,

    I'm trying to only show specific sheets per user using the environ variable and this code seems to work for the single user / sheet but the master user does not function correctly i.e. the code does not show all sheets, this is the code I am using:

    Option Explicit
    
    Private Sub Workbook_Open()
        Dim UserList As Variant
        Dim SheetList As Variant
        Dim i As Integer, ShowSheet As Integer, j As Integer
        Dim MasterUser As String, CurrentUser As String
        
        UserList = Array("John", "Joe")
        SheetList = Array("US", "Combined")
        
        'this user can see all ** the sheets
        MasterUser = "Jane"
        
        'see who the user is
        CurrentUser = Environ("username")
        
        'set ShowSheet to -1 so no sheets are shown if the user isn't found
        ShowSheet = -1
        
        'find the index ** the correct sheet for this user
        For i = LBound(UserList) To UBound(UserList)
            If UCase(UserList(i)) = UCase(CurrentUser) Then
                ShowSheet = i
                Exit For
            End If
        Next i
        
        'hide all sheets except the one the user should see
        With ThisWorkbook
            For j = LBound(SheetList) To UBound(SheetList)
                If j = ShowSheet Or CurrentUser = UCase(MasterUser) Then
                    .Sheets(SheetList(j)).Visible = xlSheetVisible
                Else
                    .Sheets(SheetList(j)).Visible = xlSheetVeryHidden
                End If
            Next j
        End With
    End Sub
    Does anyone know why the above code does not respect the Master User "Jane" should be able to see all sheets?



    Original source for this code was found here:

    HTML Code: 
    Last edited by byte; 03-10-2014 at 06:13 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Username and Password Form - Show Username in Sheet
    By ryan180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 07:06 PM
  2. Restrict HIDE / UNHIDE sheets by Username
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2012, 11:47 PM
  3. Using Userform to Hide/Show specific Sheets in Work Book
    By Craigs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2011, 05:40 AM
  4. Use checkbox to show/hide sheets?
    By Zheno in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-03-2010, 02:49 PM
  5. Hide then show specific column
    By littleandyjai in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 02-14-2010, 07:42 PM

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