VBA Code - Unhide multiple sheets with Password

StuartUK

New Member
Joined
May 18, 2011
Messages
4
Hello all :)

Am trying to find the VBA code to "ask a user for the password to unhide multiple sheets/tabs"

I have got the script for unhiding all sheets which is:

Sub Sheets_Unhide()

Dim sh As Worksheet
For Each sh In Worksheets
sh.Visible = True
Next
End Sub

What i would like though is for it to prompt with a password first before the code is executed for unlocking 50 odd sheets....
Is it possible ?
I know its not 100% fool proof, but would do for what i need! :)
cheers
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try

Code:
Sub Sheets_Unhide()
Dim sh As Worksheet
If InputBox("Enter password") <> "passw" Then
    MsgBox "Wrong password"
    Exit Sub
End If
For Each sh In Worksheets
    sh.Visible = xlSheetVisible
Next
End Sub
 
Upvote 0
Welcome to the board.
Try:
Rich (BB code):
Sub Sheets_Unhide()

Dim sh As Worksheet
Dim myPassword as String
myPassword = "Unicorn"
If InputBox("Please enter password to show sheets: ") = myPassword Then
  Application.ScreenUpdating = False
  For Each sh In Worksheets
    sh.Visible = True
  Next sh
  Application.ScreenUpdating = True
Else
  MsgBox("Incorrect password, macro stopping")
End If
End Sub
Change part in red to whatever your password is, but make sure it's surrounded by speach marks.
 
Upvote 0
Thank you kindly for the reply! :) :)
It works a treat!!! :)

Is there a way to make excel run a macro when the user goes to quit that spreadsheet ?

(I have a macro that hides the selected records, but just in case the user forgets to run the macro which hides them all, is there a command to make it do it before the spreadsheet closes ?)

Cheers :)
 
Upvote 0
Press ALT + F11 to open the Visual Basic Editor, in the Project window double click ThisWorkbook and paste in

Rich (BB code):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call nameofyourmacro
End Sub

change the name of the macro to suit.
 
Upvote 0
Wow!
liking these quick replies!
Thank You!! :)

All works a treat now my spreadsheet/staff planner.... just to keep 1 person happy, have to put these macros in to hide certain worksheets despite not containing any important info!
 
Upvote 0
Is there a way to insert code so that if the sheets do not need to a password to unhide them it will just unhide them but if a password is required then the user will be prompted for a password?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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