Forum Discussion
NE1Know
Jun 30, 2022Copper Contributor
Shared Excel File - Restricting Edits to Author
Like many companies we have shared drives with files that anyone can access and edit. Is there a way for me to create a file and save it so I can open it, edit it, and save it without entering a pas...
mtarler
Jun 30, 2022Silver Contributor
NE1Know Well if you are going to open the file in your desktop Excel you can use Macros to do this. Here is the code you want to have in "ThisWorkbook" sheet:
Private Const Owner = "Your UserName"
Private Const PW = "password"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
Call sh.Protect(PW)
Next
End Sub
Private Sub Workbook_Open()
If Application.UserName = Owner Then
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
Call sh.Unprotect(PW)
Next
End If
End SubI have attached a sample sheet and included a button that will tell you your User Name
To get in and edit you click Alt-F11 to open the VB window and then right click 'ThisWorkbook' and then select Show Code:
If you don't see this menu on the left try clicking Ctrl-R
That all said, DO NOT consider this high security by ANY means.