Question about worksheet protection?

mattbird

Active Member
Joined
Oct 15, 2013
Messages
305
Office Version
  1. 2016
Hi,

I have protected my workbook and have found one of my button is not working. The button un-hides a tab normally when the sheet protection is on by now I have protected the workbook it gives a run-time error '1004' unable to set the visible properties of the worksheet class. I can't work out how to get it to work the code I am currently using is below:

Code:
Sub BCMDatabase_ViewStats_TextBox1_Click()    Sheets("Stats 1").Visible = True
    Application.Goto Worksheets("Stats 1").Range("B5")
    
End Sub

One the sheet opens I then have another button on the new sheet (Stats 1) which returns the user to the main sheet (BCM Database) and hides the tab gain, But again I get the same message run-time error '1004' unable to set the visible properties of the worksheet class. The code I am using for the return is below:

Code:
Sub Stats1_Return_TextBox1_Click()    Application.Goto Worksheets("BCM Database").Range("L15")
    Sheets("Stats 1").Visible = False
    
End Sub


Why is this happening and how do I get the codes to work when the workbook is protected?

Matt
 
Last edited:
I tried your latest code, without incident (meaning no problems). It worked fine passing right thru the code line .Visible = True
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Is that with the Tab hidden and workbook and worksheet protection on on both sheets? even when I play the code it comes up with the same error.
 
Upvote 0
Here's the First Macro (used)..

Code:
Sub Foo()  'Standard Macro to Make the Sheet "Stats 1" visible and unprotected
With Sheets("Stats 1")
             .Unprotect Password:="meme"
             .Visible = True
             .Application.Goto Worksheets("Stats 1").Range("B5")
        End With
End Sub

Then the code placed in the code sheet of "Stats 1"...

Code:
Private Sub Worksheet_Deactivate()   ' when you leave the Stats sheet this macro automatically runs..
If Me.Name = "Stats 1" Then
        With ActiveSheet
            .Protect Password:="meme"
            .Visible = False
        End With
    End If
End Sub
 
Upvote 0
Correction... code should be...

Rich (BB code):
Private Sub Worksheet_Deactivate()   ' when you leave the Stats sheet this macro automatically runs..
If Me.Name = "Stats 1" Then
        With Me
            .Protect Password:="meme"
            .Visible = False
        End With
    End If
End Sub
 
Upvote 0
Still getting same error and debug highlights .Visible = True. sorry for the problem, but do appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,216,104
Messages
6,128,856
Members
449,472
Latest member
ebc9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top