(Solved) – Unable to set the text property of the characters class

(solved)-–-unable-to-set-the-text-property-of-the-characters-class

This code protects all sheets except for one sheet. This works if the worksheets are protected, but gives me an error message when they are not protected:

Dim wSheet As Worksheet
    Dim wb As Workbook
    Dim ws As Worksheet

    Set wb = ThisWorkbook
    Set ws = wb.Sheets(1)


        Application.ScreenUpdating = False

            For Each wSheet In Worksheets
                If wSheet.Name = "Overtime" Then
                    wSheet.Unprotect Password:="12345"
                    ws.Shapes("Rectangle_LOCK").TextFrame.Characters.Text = "Vérouiller"
                ElseIf wSheet.ProtectContents = True Then
                    wSheet.Unprotect Password:="12345"
                    ws.Shapes("Rectangle_LOCK").TextFrame.Characters.Text = "Vérouiller"
                Else
                    wSheet.Protect Password:="12345"
                    ws.Shapes("Rectangle_LOCK").TextFrame.Characters.Text = "Déverrouiller" 'THIS IS WHERE IT GIVES ME THE ERROR

                End If
            Next wSheet

 Application.ScreenUpdating = True

Leave a Reply

Your email address will not be published. Required fields are marked *