vba with password

Vtookup

Board Regular
Joined
May 30, 2017
Messages
123
Office Version
  1. 2016
  2. 2013
Hi all.
i need help with vba code to unhide sheets.
i have 6 sheets in a workbook. by default, 3 worksheet in xlsheetveryhidden mode.
i would like a vba code to show those hidden sheet if password is entered.
Thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Vtookup,

Try this code.

Code:
Sub showveryhiddensheets()

Password = InputBox("Enter a password to unhide sheets", "Unhide Very Hidden Sheets")

If Password = "Vtookup" Then
    For i = 1 To Sheets.Count
        If Sheets(i).Visible = xlVeryHidden Then
            Sheets(i).Visible = True
        End If
    Next i
Else
MsgBox "wrong password"
End If
End Sub
 
Upvote 0
Thanks Zubair Muhammad.
it works but i want it to be temporary.
those sheets return to very hidden when restarting the file.
so by default those files are not visible.
 
Upvote 0
Hi,

In that case you can write a macro that will make the 3 sheets very hidden whenever the workbook is opened

Code:
Sub auto_open()
Sheets("sheet2").Visible = xlVeryHidden
Sheets("sheet4").Visible = xlVeryHidden
Sheets("sheet6").Visible = xlVeryHidden
End Sub
 
Upvote 0
Hi again.
sorry for the confusion.
my intention is...
1. when the file is open, the hidden sheets should remain hidden until password is entered. 2. and if it's not to much to ask, separate codes to hide those very hidden sheets again. no password necessary.
thanks for your time and help.
 
Upvote 0
This simple code will make those sheets very hidden again. You can assign this macro to a button/shape.
Just modify the sheetnames according to your situation

Code:
Sub MakeVeryHiddenAgain()
Sheets("sheet2").Visible = xlVeryHidden
Sheets("sheet4").Visible = xlVeryHidden
Sheets("sheet6").Visible = xlVeryHidden
End Sub
 
Upvote 0
Zubair Muhammad,
it work perfectly. Thank you.
just one more question...
can the password box show encryption like asterisks instead of readable password?
 
Upvote 0
Yes its very much possible. I know of 2 ways

1) Use a Userform with a Textbox
2) Using Windows API

Have you used Userforms before?
 
Upvote 0
Yes its very much possible. I know of 2 ways

1) Use a Userform with a Textbox
2) Using Windows API

Have you used Userforms before?

I wish to know the use of the API

And I am sure with the userform textbox, you have to set the password = textbook.value
Correct?
Regards
Kelly
 
Upvote 0
I wish to know the use of the API

And I am sure with the userform textbox, you have to set the password = textbook.value
Correct?
Regards
Kelly

Yes. But you have to Set the passswordChar property of TextBox as "*" in order to encrypt the password. This is what Vtookup needs.
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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