• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Graphs Stop Macro to Protect WB [SOLVED]

J G

Member
I have this code to protect all worksheets and enable some formatting.

Code:
Sub ProtectSheets()
Dim wsheet As Worksheet
For Each wsheet In Worksheets
wsheet.Select
ActiveSheet.Protect Password:="ABC", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
 
Next wsheet
End Sub

My problem is that the second tab in the workbook contains graphs and the marco will protect the second tab but stops there. How do I correct this and make the macro run through the whole workbook?

Thanks,
JG
 
Instead of selecting each sheet, try to set the protection directly.
Code:
Sub ProtectSheets()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Protect Password:="ABC", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True

Next wsheet
End Sub
 
Back
Top