Gringoire
Board Regular
- Joined
- Nov 18, 2016
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hi guys,
I have a protected workbook with several protected sheets.
Sheets are protected through a very simple routine:
Everything works perfectly except when I just open the file.
After the file is just opened, even if protection routine includes UserInterfaceOnly:=True , VBA seems not allowed to do any modification. It is even not possible to change a value in a cell because I receive a runtime error 1004: Cell is in a protected sheet...
If I apply the above mentioned routine two times: once with stato=False to unprotect the sheets and once with stato=True to protect the sheets again, my workbook starts to work perfectly, even if the sheets are protected as they were before.
Someone could please explain what I'm doing wrong?
thanks.
I have a protected workbook with several protected sheets.
Sheets are protected through a very simple routine:
VBA Code:
Sub lockSheet(foglio As Worksheet, stato As Boolean)
'===========================================
' Protegge / sprotegge un FOGLIO Excel
' se stato = True protegge, False sprotegge.
'===========================================
Dim PWD_F As String
PWD_F = ActiveWorkbook.Sheets(shDEV_Utilities.Name).Range("NR_pwdsh") 'PWD foglio
If stato = True Then 'Proteggo il foglio
foglio.Protect Password:=PWD_F, _
DrawingObjects:=True, Contents:=True, Scenarios:=True, _
UserInterfaceOnly:=True, _
AllowFormattingCells:=False, AllowFormattingColumns:=True, AllowFormattingRows:=False, _
AllowInsertingColumns:=False, AllowInsertingRows:=False, AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, AllowDeletingRows:=False, _
AllowSorting:=False, AllowFiltering:=True, AllowUsingPivotTables:=False
Else 'Sproteggo il foglio
foglio.Unprotect (PWD_F)
End If
End Sub
Everything works perfectly except when I just open the file.
After the file is just opened, even if protection routine includes UserInterfaceOnly:=True , VBA seems not allowed to do any modification. It is even not possible to change a value in a cell because I receive a runtime error 1004: Cell is in a protected sheet...
If I apply the above mentioned routine two times: once with stato=False to unprotect the sheets and once with stato=True to protect the sheets again, my workbook starts to work perfectly, even if the sheets are protected as they were before.
Someone could please explain what I'm doing wrong?
thanks.