ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Simple workbook Protect (https://www.excelbanter.com/excel-programming/426613-simple-workbook-protect.html)

LiAD

Simple workbook Protect
 
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

Jacob Skaria

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

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

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


LiAD

Simple workbook Protect
 
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

"Jacob Skaria" wrote:

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

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

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



All times are GMT +1. The time now is 03:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com