Before running this code, can you check if the sheet is already
protected or not. Could be that your sheet is already protected and
you are trying to re-protect it using this code.

Nishant
On Jun 23, 6:05 pm, Gert <gertvan...@gmail.com> wrote:
> hi All, thought this would be easy but I get:
>
>     Run-time error 1004. You cannot use this macro on a protected
> sheet....
>
> Anyone knows what's going on re. my code below? Just the protecting
> works but I would like to hide all formula's and then I get the error
> though my sheets are not protected.
>
> Thanks for any reply,
> Gert
>
>     Public Sub ProtectAllSheets()
>     Dim objSheet As Worksheet
>
>     For Each objSheet In Worksheets
>     Cells.SpecialCells(xlCellTypeFormulas).Select
>     Selection.Locked = True
>     Selection.FormulaHidden = True
>     Next objSheet
>
>         'Protecting all worksheets with(out) password
>     For Each objSheet In Worksheets
>             If objSheet.ProtectContents = False Then objSheet.Protect
> ""
>     Next objSheet
>
>     End Sub
--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to