Excel – Error-1004 in Excel VBA- Unable to set the visible property of the worksheet class

excelvba

With the help of Excel forum, I have created a user login form where I have 5 users. Each user can have access to the sheets assigned to him/her only. This is working fine. But now I have protected the "workbook structure" so as to avoid users' adding/deleting sheets. Then I login again, and instead of displaying the login form, the error message pops up in Excel VBA:

Error-1004 Unable to set the visible property of the worksheet class

When I debug the error is highlighted in the following codes where the visible property of the worksheet is set as "True", "False" or "xlSheetVeryHidden".

Private Sub Workbook_Open()
    Dim wsSht As Worksheet

    Worksheets("Splash").Visible = True
    Worksheets("Users").Visible = False
    For Each wsSht In Worksheets
        If Not wsSht.Name = "Splash" Then wsSht.Visible = xlSheetVeryHidden
    Next wsSht
    With Worksheets("Splash")
        .Visible = True
        .Activate
    End With
    frmLogin.Show
    bBkIsClose = False

End Sub

Is there a way to correct this so as I can access the login form as I did prior to password protecting the "workbook structure"?

Best Answer

Here is another concern about this.

You can NOT hide ALL of the worksheets in a workbook. As such if you know you are going to have at least 1 sheet that will ALWAYS be visible, exclude it from the hiding process.

Related Topic