DEFAULT UNPROTECTED SHEET UPON OPENING EXCEL FOR SELECT USERS

markkuznetsov1

New Member
Joined
Sep 23, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a code for a sheet that should always be protected for all users upon opening unless you are in an "admin" cell on another sheet called "AuthUsers". The page should open protected for all users and they can only hit a button that has the code to unprotect,run macro, and re protect at the end. This is what I have so far...I know it is wrong but I was trying multiple codes and this is my final. How can I fix it?

Users = Environ("UserName")
Set D = Worksheets("AuthUsers").Range("A3:A4").Find(Users, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If ThisWorkbook.Path = Environ("UserName") Then ThisWorkbook.Worksheets("EDP #S").Unprotect ("EDPPassword")

Else: If ThisWorkbook.Path <> Environ("UserName") Then ThisWorkbook.Worksheets("EDP #S").Protect ("EDPPassword")
End If

I started from this block and tried to mimic it. (used for read only)

Users = Environ("USERNAME")
Set c = Worksheets("AuthUsers").Range("A1:A100").Find(Users, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If c Is Nothing Then
Application.DisplayAlerts = False
On Error Resume Next
If ThisWorkbook.Path <> vbNullString Then ThisWorkbook.ChangeFileAccess xlReadOnly
On Error GoTo 0
Application.DisplayAlerts = True
End If
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
(Solved) cross post.....does read only, protected, and hides sheet based on admin user/users

 
Upvote 0
Solution
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

If you do cross-post in the future and also provide links initially - not after the problem is solved on the other forum, then there shouldn’t be a problem.
No further action is required in this thread.
 
Upvote 0

Forum statistics

Threads
1,215,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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