Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / October 2007

Tip: Looking for answers? Try searching our database.

bug in protect-unprotect macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stef - 09 Oct 2007 19:43 GMT
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....
Barb Reinhardt - 10 Oct 2007 00:08 GMT
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

Signature

HTH,
Barb Reinhardt

> Excel 2002 SP3
> Win XP Pro
[quoted text clipped - 21 lines]
>
> Be easy on me as I am a newbie at XL macros/VBA....
stef - 10 Oct 2007 02:01 GMT
Bard, same as the one Jim posted and I thank both very much for it--it
does work and makes my life easier.

> I did tweak it a bit, but didn't have problems where you did.
>
[quoted text clipped - 10 lines]
> Application.ScreenUpdating = True
> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.