Hi All,

I've been using the following code successfully for years. Today I would get the error 1004:Unable to set the visible property of the worksheet class. All my searches came up with someone not realizing they had protected the workbook. As you can see, the first thing I do before trying to set the worksheet visible is to unprotect the workbook. In frustration and on a lark I tried .Sheets("items").Visible = True and it worked. These kind of intermittent errors in Excel VBA are very frustrating. Can anyone tell me what I am doing wrong?

Thanks.


Sub Unprotect()

Dim c As Integer
Dim wkbk As Workbook

Application.ScreenUpdating = False

    With Application.FileSearch
        .LookIn = ThisWorkbook.Path
        .FileType = msoFileTypeExcelWorkbooks
            If .Execute > 0 Then
                For c = 1 To .FoundFiles.Count
                    Set wkbk = Workbooks.Open(.FoundFiles(c))
                    With wkbk
                        .Unprotect "mypassword"
                        .Sheets("items").Visible = xlVisible
                        .Save
                        .Close
                    End With
                Next c
            Else
                MsgBox "No workbooks"
            End If
    End With

Application.ScreenUpdating = True
    
End Sub