VBA for Hiding\unhiding Very hidden sheet via password

Alisya

Well-known Member
Joined
Nov 27, 2008
Messages
532
Hi, i need a code that will unhide all veryhidden sheets, but when the user executes command button, i would like a input box which will ask for a password, if the pass word is correct then run macro, similary i would like a macro that will hide the followings sheets as veryhidden with input box prompt for password. Password should be test

"Test1","Test2","Test3","Test4"
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Something like this should get you started.

Code:
Sub test1()
Dim ws As Worksheet
Dim wb As Workbook
Dim i As Integer
Dim strResponse As String

strResponse = InputBox("Please enter the password.", "Password")

If strResponse = "Test" Then

    i = 1
    
    Do Until i > Sheets.Count
    
        Set ws = Sheets(i)
        ws.Visible = xlSheetVisible
        i = i + 1
        
    Loop

Else

MsgBox "The passowrd entered is incorrect.", vbCritical, "Incorrect Password"

Exit Sub

End If

End Sub

HTH
Roger
 
Upvote 0
Ok, thats great now how do i do the opposite, where i want to hide sheets as very hidden?

Something like this should get you started.

Code:
Sub test1()
Dim ws As Worksheet
Dim wb As Workbook
Dim i As Integer
Dim strResponse As String
 
strResponse = InputBox("Please enter the password.", "Password")
 
If strResponse = "Test" Then
 
    i = 1
 
    Do Until i > Sheets.Count
 
        Set ws = Sheets(i)
        ws.Visible = xlSheetVisible
        i = i + 1
 
    Loop
 
Else
 
MsgBox "The passowrd entered is incorrect.", vbCritical, "Incorrect Password"
 
Exit Sub
 
End If
 
End Sub

HTH
Roger
 
Upvote 0
I used the same password as above:
Code:
Sub MakeHidden()
strResponse = InputBox("Please enter the password.", "Password")
If strResponse = "Test" Then
'Loop through all worksheets
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name = "Test1" _
            Or ws.Name = "Test2" _
            Or ws.Name = "Test3" _
            Or ws.Name = "Test4" Then
            ws.Visible = xlSheetVeryHidden
        End If
    Next ws
    MsgBox "Some Worksheets now hidden."
Else
    MsgBox "The passowrd entered is incorrect.", vbCritical, "Incorrect Password"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

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