How to Block other users from viewing Excel sheets

Krishnab4u

New Member
Joined
Jul 16, 2018
Messages
34
Dear All,
I used Environ "User Name" method in my workbook to assign Visibility of sheets with respect to the users.
Now, I dont want any of the users other than in the list to see all the sheets except one or two.
Please guide how to do the same.

Thank You.

Regards
Krishnamoorthy S
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
if the logged on user is <> to an environ then that should do it, you need to make sure that when closed all potential sheets are xlveryhidden, then you control who can see as opened and the lack of macro will not let them bypass the hidden code, you will need to password your module as well
 
Upvote 0
Something like this...


Code:
Private Sub Workbook_Open()
Dim Dict    As Object: Set Dict = CreateObject("Scripting.Dictionary")
Dim CurUser As String: CurUser = Environ("UserName")
Dim wsArr() As Variant: wsArr = Array("Sheet2", "Sheet3") 'Sheets that need to be hidden or unhidden


Dict.Add "User1", 1
Dict.Add "User2", 1
Dict.Add "User3", 1
Dict.Add "User4", 1 'Add all of the users who should be able to see the sheets


For i = 0 To UBound(wsArr)
    If Dict.exists(CurUser) Then
        Sheets(wsArr(i)).Visible = xlSheetVisible
    Else
        Sheets(wsArr(i)).Visible = xlSheetVeryHidden
    End If
Next i


End Sub
 
Upvote 0
On that last I force either to upper or lower case the ENVIRON string, that way we don't worry about exact match issues.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top