vba with password

Vtookup

Board Regular
Joined
May 30, 2017
Messages
137
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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