Simple workbook Protect

L

LiAD

morning,

could some-one please give me a very simple code for unprotecting and then
reprotecting an entire workbook (it contains three sheets)? I am looking for
a code to replace the protect sheet version of

Sheets("UP4 Données").Unprotect Password:="ABCDEFGH"

to the workbook version.

I have other code driven by macro buttons which I will put in between the
unprotect and protect codes just for reference.

Thanks
LiAD
 
J

Jacob Skaria

Sub ProtectAllSheets()
For Each Shts In ThisWorkbook.Worksheets
Shts.Protect Password:="ABCDEFGH"
Next
End Sub

If this post helps click Yes
 
L

LiAD

Hi,

Thanks for your help again.

I have pasted the protect macro into a save maro and also a calculation
macro. It works well with the save one but not with the calculation one.
Would you know why?

The line it points to as faulting is - Range("J38").Value =
Range("J38").Value - 1

The full macro is below.

Thankyou

Sub UtiliséBobine15()

For Each Shts In ThisWorkbook.Worksheets
Shts.Unprotect Password:="ABCDEFG"
Next

Call AddToLog("UtiliséBobine15")

With Sheet1 ' Changer to suit
If Range("J38").Value <> "" Then ' Change J38 to suit
Range("J38").Value = Range("J38").Value - 1
End If
End With
For Each Shts In ThisWorkbook.Worksheets
Shts.Protect Password:="ABCDEFG"
Next
End Sub

Sub AddToLog(MacName As String)

For Each Shts In ThisWorkbook.Worksheets
Shts.Unprotect Password:="ABCDEFG"
Next

Dim NextRow As Long

With Worksheets("Log")
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(NextRow, "A").Value = MacName
.Cells(NextRow, "B").Value = Now
End With

For Each Shts In ThisWorkbook.Worksheets
Shts.Protect Password:="ABCDEFG"
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top