Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unprotecting hidden worksheets 1

Status
Not open for further replies.

Airbisk

Technical User
Apr 28, 2009
43
GB
I have called the code below within a written macro. The code has caused some problems after protecting some hidden worksheets that require to be unprotected.

Could you help me by pointing me in the right direction/code so that I only protect the visible sheets in my workbook.

If you require more details please let me know.

Thanks in advance.

Steve



Sub ProtectSheets()

Dim wSheet As Worksheet

For Each wSheet In Worksheets

If wSheet.ProtectContents = True Then

wSheet.Unprotect Password:=" "

Else

wSheet.Protect Password:=" "

End If

Next wSheet

End Sub
 


Hi,
Code:
Sub ProtectSheets()

Dim wSheet As Worksheet

    For Each wSheet In Worksheets
      if wsheet.visible = xlsheetvisible then
        If wSheet.ProtectContents = True Then

            wSheet.Unprotect Password:=" "

        Else

            wSheet.Protect Password:=" "

        End If
     end if
    Next wSheet

End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks skip

For visible sheets you use....

if wsheet.visible = xlsheetvisible then

For reference what if you change this for hidden sheets what would you use then?
 
Its okay Skip just messed about and worked it out...

if wsheet.visible = xlsheethidden then

Easy stuff when you know how!!!

Anyway thanks for the earlier solution
 


There are 2 hidden states

xlSheetHidden
xlSheetVeryHidden

Check out HELP for more info.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top