Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Protect All Sheets code not working

Thisworkbook refers to the workbook containing the code:

Sub ProtectSheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect Password
ws.Protect Password, True, True, True, True
Next ws
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy




"Steve" wrote in message
news:3ff2ed17$0$15602$afc38c87@...
Hi everyone. I have the following code that protects all sheets in the
workbook. I have now copied this code and inserted it into my personal
workbook, so I can run it on all files. But it doesn't work. I'm

assuming
it is protecting and unprotecting sheets in my personal workbook only, and
NOT the active workbook. What should I do? Thanks!!

Sub ProtectSheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password
ws.Protect Password, True, True, True, True
Next ws
Application.ScreenUpdating = True
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protect VB-code mohavv Excel Discussion (Misc queries) 1 December 2nd 07 10:20 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
Code to protect sheet Conditional Formatting Excel Worksheet Functions 1 December 21st 05 11:04 PM
password protect vba code greg Excel Discussion (Misc queries) 3 December 8th 04 04:03 PM
Protect Code JC[_7_] Excel Programming 4 November 25th 03 03:52 PM


All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"