Hello,
I currently use a VBA to auto protect my worksheets upon closing the document. If users do not have a password, they can view the document but, they cannot edit.
I want to allow those who do not have the password to only be able to edit a range of cells. How should I write the code instead?
My current code is:
Private Sub Workbook_Open()
MsgBox ("REMINDER!! Please enter your LE02 estimates by the deadline of MARCH 10.")
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = InputBox(Prompt:="Password", _
Title:="Enter Password", Default:="User Password")
If strPassWord = "mypassword" Then
Call UnlockSheet(Sheets("Sheet1"), strPassWord)
Call UnlockSheet(Sheets("Sheet2"), strPassWord)
Call UnlockSheet(Sheets("Sheet3"), strPassWord)
Else
Call LockSheet(Sheets("Sheet1"))
Call LockSheet(Sheets("Sheet2"))
Call LockSheet(Sheets("Sheet3"))
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = "mypassword"
Call LockSheet(Sheets("Sheet1"))
Call LockSheet(Sheets("Sheet2"))
Call LockSheet(Sheets("Sheet3"))
End Sub
Private Sub LockSheet(sheet As Worksheet)
sheet.Protect Password:=strPassWord, DrawingObjects:=True, Contents:=True, Scenarios:=True
sheet.EnableSelection = xlNoSelection
End Sub
Private Sub UnlockSheet(sheet As Worksheet, strPassWord As String)
sheet.Unprotect Password:=strPassWord
End Sub
I currently use a VBA to auto protect my worksheets upon closing the document. If users do not have a password, they can view the document but, they cannot edit.
I want to allow those who do not have the password to only be able to edit a range of cells. How should I write the code instead?
My current code is:
Private Sub Workbook_Open()
MsgBox ("REMINDER!! Please enter your LE02 estimates by the deadline of MARCH 10.")
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = InputBox(Prompt:="Password", _
Title:="Enter Password", Default:="User Password")
If strPassWord = "mypassword" Then
Call UnlockSheet(Sheets("Sheet1"), strPassWord)
Call UnlockSheet(Sheets("Sheet2"), strPassWord)
Call UnlockSheet(Sheets("Sheet3"), strPassWord)
Else
Call LockSheet(Sheets("Sheet1"))
Call LockSheet(Sheets("Sheet2"))
Call LockSheet(Sheets("Sheet3"))
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = "mypassword"
Call LockSheet(Sheets("Sheet1"))
Call LockSheet(Sheets("Sheet2"))
Call LockSheet(Sheets("Sheet3"))
End Sub
Private Sub LockSheet(sheet As Worksheet)
sheet.Protect Password:=strPassWord, DrawingObjects:=True, Contents:=True, Scenarios:=True
sheet.EnableSelection = xlNoSelection
End Sub
Private Sub UnlockSheet(sheet As Worksheet, strPassWord As String)
sheet.Unprotect Password:=strPassWord
End Sub