rights management

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
I'd like to hide / unhide specific sheets, if the user is known to the workbook

its normally on a secure network, but the book would be copied between departments

the code is as secure as i can make it, so i can hard code the names inside the code

senario

userA has all rights, as workbook opens checks against network ID and ensures sheets are unhidden

userB doesnt have all rights, so when the book open, we make the sheets xlhidden

unknown user, close further pages

any clues where best to start or some draft code that can be adjusted
 
Why the ON ERROR?

Maybe use SELECT:-
Rich (BB code):
Select case Environ("username")
  Case UserA, UserB, UserC, UserD, UserE, UserF, UserG, UserH, UserI ' etc
    'Authorised
    Sheets("2").Visible = True
    Sheets("1").Visible = xlVeryHidden
  Case Else
    'Not Authorsied
    Sheets("1").Visible = True
    Sheets("2").Visible = xlVeryHidden
End Select

Although I might do something like this:-
Code:
option explicit
option compare text
 
sub openup()
 
dim vauth as variant
dim i as integer
 
[COLOR=green]'Assume Not Authorsied[/COLOR]
Sheets("1").Visible = True
Sheets("2").Visible = xlVeryHidden
 
vAuth=array("mole","fred","some1else","etc")
 
for i=lbound(vAuth) to ubound(vAuth)
  if environ("username")=vAuth(i) then
    [COLOR=green]'Deffo Authorised[/COLOR]
    Sheets("2").Visible = True
    Sheets("1").Visible = xlVeryHidden
    exit sub [COLOR=green]' if you don't intend to do anything else in this sub[/COLOR]
  endif
next i
 
end sub

ON ERROR, because I always miss something, I take them out when I'm happy its stable.
I like this, good to test it in my work environment, then build into the workbook
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Why hard code the names, it makes it a pain to manage if you have quiet a few users, a lookup sheet (xlveryhidden) and VBA find is just as quick and a bit easier to manage, in fact you could then check the offset for a flag of your choice to allow/disallow whatever you want.
 
Upvote 0
eight users, one department, same office to manage with full rights, and all others won't have full access, its not too onerous
 
Upvote 0
Its been a good few days in test and appears very stable

one possible issue

Code:
    who = Environ("username")

    vauth = Array("mole","fred","some1else","etc")

    For i = LBound(vauth) To UBound(vauth)
        If Environ("username") = vauth(i) Then

is there any way to loose what appears to be case sensitivity on the user name (environ) I used all the staffs email addresses, but one or two just don't seem to work
 
Upvote 0
Code:
who = lcase(Environ("username"))
 
Upvote 0
thanks, hadn't even thought like that
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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