Protecting Multiple Sheets

G

Guest

I entered the following code

Sub ProtectAll()

Dim wSheet As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to protect all worksheets",
"Password Input")
For Each wSheet In Worksheets
wSheet.Protect Password:=Pwd
Next wSheet

End Sub




But when i run the code i get an error and all it says is "400", can someone
hep me, i am trying to protect 52 sheets at one time

Thanks
 
G

Guest

I copy and pasted your exact code and it works, even tried with 100 sheets.
Where are you putting your code and what version?
 
G

Guest

I am right clicking on the worksheet tab and clicking on view code and then
entering the code, then go to the worksheet and click on macors and run the
macro using version 2003, am i putting it in the wrong area?
 
P

Peo Sjoblom

Yes you are, you should put it in a regular module, press alt + F11, select
the file in the project pane to the left and select insert module, that's
where to put it Then you run the macro from
Alt + F8 or attach it to a button or a menu
 

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