![]() |
Urgent - Simple Workbook Protect
Hi,
I am using the macro attached below to drive a series of worksheets, graphs etc. I would like to change the protect and unrpotect sheet parts to protect/unp the whole workbook as that will also lock the sheet tab names. Could somebody tell me how please? When I try I get loads an error Thanks LiAD Sub BobineProduit15() Sheets("UP1 Production").Unprotect Password:="ABCDEF" Sheets("UP4 Données").Unprotect Password:="ABCDEF" Call AddToLog("BobineProduit15") If myT = 0 Then myT = Now With Sheet4 If Now - myT 1 / 1440 Then 'Note - use 1440 (60*24), not 14400 ..Range("L6").Value = 0 Else ..Range("L6").Value = .Range("L6").Value + 1 End If myT = Now End With 'Add 1 to I38 With Sheet1 If IsNumeric(.Range("J38").Value) Then ..Range("J38").Value = .Range("J38") + 1 Else MsgBox "J38 on sheet1 isn't a number!" End If End With Sheets("UP1 Production").Protect Password:="ABCDEF" Sheets("UP4 Données").Protect Password:="ABCDEF" End Sub Sub AddToLog(MacName As String) Sheets("Log").Unprotect Password:="ABCDEF" 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 Sheets("Log").Protect Password:="ABCDEF" End Sub |
Urgent - Simple Workbook Protect
You can protect and unprotect sheets with workbook protection enabled.
So just go ahead and protect the workbook once and leave protected. If you do want to protect/unprotect add these lines before and after the sheet protection lines. ActiveWorkbook.Unprotect Password:="justme" Sheets("UP1 Production").Unprotect Password:="ABCDEF" Sheets("UP4 Données").Unprotect Password:="ABCDEF" other code here....................... Sheets("UP1 Production").Protect Password:="ABCDEF" Sheets("UP4 Données").Protect Password:="ABCDEF" ActiveWorkbook.Protect Password:="justme", Structu=True, Windows:=True Gord Dibben MS Excel MVP On Wed, 8 Apr 2009 06:31:01 -0700, LiAD wrote: Hi, I am using the macro attached below to drive a series of worksheets, graphs etc. I would like to change the protect and unrpotect sheet parts to protect/unp the whole workbook as that will also lock the sheet tab names. Could somebody tell me how please? When I try I get loads an error Thanks LiAD Sub BobineProduit15() Sheets("UP1 Production").Unprotect Password:="ABCDEF" Sheets("UP4 Données").Unprotect Password:="ABCDEF" Call AddToLog("BobineProduit15") If myT = 0 Then myT = Now With Sheet4 If Now - myT 1 / 1440 Then 'Note - use 1440 (60*24), not 14400 .Range("L6").Value = 0 Else .Range("L6").Value = .Range("L6").Value + 1 End If myT = Now End With 'Add 1 to I38 With Sheet1 If IsNumeric(.Range("J38").Value) Then .Range("J38").Value = .Range("J38") + 1 Else MsgBox "J38 on sheet1 isn't a number!" End If End With Sheets("UP1 Production").Protect Password:="ABCDEF" Sheets("UP4 Données").Protect Password:="ABCDEF" End Sub Sub AddToLog(MacName As String) Sheets("Log").Unprotect Password:="ABCDEF" 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 Sheets("Log").Protect Password:="ABCDEF" End Sub |
All times are GMT +1. The time now is 05:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com