Urgent - Simple Workbook Protect

L

LiAD

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
 
G

Gord Dibben

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", Structure:=True, Windows:=True


Gord Dibben MS Excel MVP
 

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