MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Jan 14th, 2002, 01:04 PM   #1
Moradyn
New Member
 
Join Date: Apr 2002
Posts: 17
Default


Anyone have a link to some code that protects and unprotects multiple sheets in one go ?

Moradyn is offline   Reply With Quote
Old Apr 15th, 2002, 08:56 AM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

You cannot protect/unprotect more than one sheet at once, have you tried the following:

Worksheets("Sheet1").Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("Sheet1").Unprotect ("password")
Worksheets("Sheet2").Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("Sheet2").Unprotect ("password")

Edit as needed.
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Apr 15th, 2002, 09:01 AM   #3
shades
Board Regular
 
shades's Avatar
 
Join Date: Mar 2002
Location: Near the Land of Oz
Posts: 1,550
Default

Actually, someone gave me the following a few weeks ago. These two macros will do it for all sheets in a workbook.


Sub ProtectAll()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Protect password:="whatever", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next ws

End Sub


-----------
Sub DeProtectAll()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect password:="whatever"
Next ws

End Sub

NOTE:
"whatever" is the password (without the quotes) you supply
_________________
- old, slow, and confused
... but at least I'm inconsistent -

[ This Message was edited by: shades on 2002-04-15 08:02 ]
shades is offline   Reply With Quote
Old Apr 15th, 2002, 09:24 AM   #4
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Shades code will work if you want to do all of the sheets of a workbook, but not if you only want to do some of the worksheets. If you want to use a for loop, then you will have to do something like the following:

Sub ProtectWS()
Dim ws As Worksheet
Set WSArray = Sheets(Array("Sheet1", "Sheet3"))
For Each ws In WSArray
ws.Protect password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
end sub

Edit as needed.

__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Jul 20th, 2010, 10:40 AM   #5
Agieseke
New Member
 
Join Date: Jul 2010
Posts: 3
Red face Re: Protecting & Unprotecting multiple sheets.

I am new to VBA code, so I don't fully understand. If I insert this into my VBA code, what sheet do I use - This Workbook or Module? Also, once I have it inserted, how do I run it? Sorry for the basic questions, but until I get training (sometime in September) I have to go this route.
Agieseke is offline   Reply With Quote
Old Jul 20th, 2010, 10:44 AM   #6
Jon von der Heyden
MrExcel MVP
Moderator
New Pool Boy
 
Jon von der Heyden's Avatar
 
Join Date: Sep 2004
Location: Greyton, South Africa
Posts: 7,960
Default Re: Protecting & Unprotecting multiple sheets.

Hi and welcome to the board!

The code you refer to should sit within a standard module. You can either run it by hitting ALT+F8 and then choosing the macro from the dialog that opens, or you can attach the macro to a forms button in one of your sheets.
__________________
Regards,
Jon von der Heyden

- Posting guidelines, forum rules and terms of use

- Try searching for your answer first, see how

- Read the FAQs

- List of BB codes

- Excel Design Solutions
Jon von der Heyden is offline   Reply With Quote
Old Jul 20th, 2010, 11:38 AM   #7
Agieseke
New Member
 
Join Date: Jul 2010
Posts: 3
Default Re: Protecting & Unprotecting multiple sheets.

Thank you so much for your assistance! This worked like a charm!!
Agieseke is offline   Reply With Quote
Old Jul 20th, 2010, 11:55 AM   #8
Agieseke
New Member
 
Join Date: Jul 2010
Posts: 3
Default Re: Protecting & Unprotecting multiple sheets.

I'm sorry, one last question. Can I modify this code to unprotect the worksheets as well? I tried the following:
Sub UnProtectWS()
Dim ws As Worksheet
Set WSArray = Sheets(Array("Sheet1","Sheet3"))
For Each ws In WSArray
ws.Unprotect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
End Sub

However, I get a Compile Error:Named argument not found, and the "DrawingObjects:" is highlighted. What am I doing wrong?

Thank you ~ Agieseke
Agieseke is offline   Reply With Quote
Old Jul 20th, 2010, 12:12 PM   #9
Jon von der Heyden
MrExcel MVP
Moderator
New Pool Boy
 
Jon von der Heyden's Avatar
 
Join Date: Sep 2004
Location: Greyton, South Africa
Posts: 7,960
Default Re: Protecting & Unprotecting multiple sheets.

Those arguments are not available when you unprotect, only when you protect. So it would be:

Code:
Sub UnProtectWS()
    Dim ws As Worksheet
    Set WSArray = Sheets(Array("Sheet1","Sheet3"))
    For Each ws In WSArray
         ws.Unprotect Password:="password"
    Next
End Sub
__________________
Regards,
Jon von der Heyden

- Posting guidelines, forum rules and terms of use

- Try searching for your answer first, see how

- Read the FAQs

- List of BB codes

- Excel Design Solutions
Jon von der Heyden is offline   Reply With Quote
Old Oct 20th, 2010, 11:42 AM   #10
jlouwagie
New Member
 
Join Date: Sep 2010
Posts: 12
Default Re: Protecting & Unprotecting multiple sheets.

I am using the above macros and have been successful in protecting multiple worksheets with a password, but I can't seem to protect them in a way that allows me to continue to use the Pivot Table Reports. Is there additional language that I can include that will select only "Use Pivot Table Reports" from the list on the "Protect Sheet" screen?
jlouwagie is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes