Hide a sheet with a password

Neflhiem

New Member
Joined
Sep 15, 2011
Messages
7
I have read now numerous posts on how to do this but i keep getting a mismatch or an out of range error.

My workbook has 13 sheets all named for each month. I have sheet13 named Sensitive routing.

if i go to VBA all my sheets in the Project window show up as "Sheet1(JAN11)" and so on ...in the properties of the sheet i want to hide, 13, it shows (name) "Sheet 13" and on down is Name "Sensitive Routing" (obviously no quotes).

Ok now my code is all botched up, because, well i stink at this and am trying to patch numerous other codes togehter.. what i have is:
Code:
Option Explicit
Dim Sheet13 As Worksheet

Sub ShowSheet()
    Const mypass = 1100
    On Error GoTo errhandler
    passtry = InputBox("Please Enter A Password To Unhide Sheet")
    If passtry <> mypass Or passtry = vbNullString Then Exit Sub
    ActiveWorkbook.Sheets(Sheet13).Visible = xlSheetVisible
errhandler:
End Sub
 
Sub HideSheet()
        ActiveWorkbook.Sheets(Sheet13).Visible = xlSheetVeryHidden
End Sub

My end state is a button the user is presented on the first page, for Command View - which will run the macro to unhide the "Sensitive Routing" tab. But if i can just get a little hellp in actually making the macro hide/unhide the sheet it would be great. Also, im seem to be a little slow today on where i need "" and where i dont - i think i have it right, now, but i could be way, way off.

Also im stuck using Excel 2007

Thanks in advance, and i will continue to scour the web for better examples ...
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try using the codename

Code:
Option Explicit

Sub ShowSheet()
    Const mypass = 1100
    On Error GoTo errhandler
    passtry = InputBox("Please Enter A Password To Unhide Sheet")
    If passtry <> mypass Or passtry = vbNullString Then Exit Sub
    Sheet13.Visible = xlSheetVisible
errhandler:
End Sub
 
Sub HideSheet()
    Sheet13.Visible = xlSheetVeryHidden
End Sub
 
Upvote 0
Hidesheet works great.. wow. simple change.. thanks..

my Showsheet now is giving a compile error: Variable not defined for passtry, ithink, yellow highlight on the Sub Showsheet() line and "passtry" from Passtry = Inputbox was highlighted (like if i used my curser.)
 
Upvote 0
Try this

Code:
Option Explicit

Sub ShowSheet()
    Const mypass As Variant = 1100
    Dim passtry As Variant
    On Error GoTo errhandler
    passtry = Application.InputBox("Please Enter A Password To Unhide Sheet", Type:=1)
    If passtry <> mypass Then Exit Sub
    Sheet13.Visible = xlSheetVisible
errhandler:
End Sub
 
Sub HideSheet()
    Sheet13.Visible = xlSheetVeryHidden
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

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