Protecting whole workbook
Thank you Norman!
It worked a charm.
Kind Regards
Tanya
Private Sub Protect_Workbook_Click() '<==== I am using a command button to
run this macro
'Protect workbook
Dim ws As Worksheet
Const PWORD As String = "BBHS"
For Each ws In ActiveWorkbook.Worksheets '<==== I replaced me with
ActiveWorkbook.
With ws
If ws.ProtectContents = False Then
.EnableSelection = xlUnlockedCells
.Protect Password:=PWORD
End If
End With
Next ws
ActiveWorkbook.Protect Password:=PWORD
End Sub
"Norman Jones" wrote:
Hi Tanya,
The code was intended as:
'<<=============
Private Sub Protect_Workbook_Open() '<<====
Dim ws As Worksheet
Const PWORD As String = ""BBHS" '<<====
For Each ws In Me.Worksheets
With ws
If .ProtectContents = False Then
.EnableSelection = xlUnlockedCells
.Protect password:=PWORD
End If
End With
Next ws
ActiveWorkbook.Protect password:=PWORD
End Sub
'<<=============
---
Regards,
Norman
|