Hi all,
I'm trying to set up protection on my excel sheet.. and the way I imagine it, would be, when someone opens the workbook, they have to input a password, if they don't or the password isn't correct, they can only observe the workbook, and can't even select cells or do anything. Then if the password is correct, the next .Protect gets applied. Which allows some things but not everything, and to get the Sheet completely unprotected, there would be a button which will ask for the Admin Password and that will unprotect it completely, so the structure is okay but.. its just not exactly right as I code it...
Can I get some help with this please?
Here is my code, and my exact question within:
Posted on Excelforum as well link: https://www.excelforum.com/excel-pr...-multiple-steps-code-example.html#post5098176
I'm trying to set up protection on my excel sheet.. and the way I imagine it, would be, when someone opens the workbook, they have to input a password, if they don't or the password isn't correct, they can only observe the workbook, and can't even select cells or do anything. Then if the password is correct, the next .Protect gets applied. Which allows some things but not everything, and to get the Sheet completely unprotected, there would be a button which will ask for the Admin Password and that will unprotect it completely, so the structure is okay but.. its just not exactly right as I code it...
Can I get some help with this please?
Here is my code, and my exact question within:
Code:
[COLOR=#333333]Sub Protect_my_sheet()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">
'Private Sub Auto_Open()
Dim Pass As Variant
Pass = InputBox("Password?")
ActiveSheet.Protect 123
Sheet1.EnableSelection = xlNoSelection
If Pass = 123 Then
Sheet1.Unprotect Pass
Sheet1.EnableSelection = xlNoRestrictions
'Why can't I add rows to a table? Also if I try adding more statements eg.:Userinterfaceonly: = True I get a syntax error??
Sheet1.Protect Password:="456", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=True, _
AllowSorting:=True, _
AllowFiltering:=True, _
AllowUsingPivotTables:=False
ElseIf Pass <> 123 Then
MsgBox "Password is incorrect. You are only allowed to observe this Workbook."
End If
</code>[COLOR=#333333] End Sub[/COLOR]
Posted on Excelforum as well link: https://www.excelforum.com/excel-pr...-multiple-steps-code-example.html#post5098176
Last edited: