View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default bug in protect-unprotect macro

I did tweak it a bit, but didn't have problems where you did.

Sub ProtectAllSheets()
Dim WS As Worksheet
Application.ScreenUpdating = False
For Each WS In ThisWorkbook.Worksheets

With WS
.Protect Password:="nosecret"
.EnableSelection = xlUnlockedCells
End With
Next WS
Application.ScreenUpdating = True
End Sub

--
HTH,
Barb Reinhardt



"stef" wrote:

Excel 2002 SP3
Win XP Pro

*Follow-up to: microsoft.public.excel.programming*

Hi,

I have a bug with the line ".EnableSelection = xlUnlockedCells" in this
macro:

Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Protect Password:="nosecret"
.EnableSelection = xlUnlockedCells
End With
Next n
Application.ScreenUpdating = True
End Sub

It's always worked in the past and I can't understand what is happening now.

Be easy on me as I am a newbie at XL macros/VBA....