ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Any way to show / hide sheets (https://www.excelbanter.com/excel-programming/442359-any-way-show-hide-sheets.html)

SteAXA

Any way to show / hide sheets
 
I need a way, when i open a workbook, to hide all sheets till the user enter
the correct password.
When the user enter the password i want be able to show all sheets.
Please, someone can help me?
Thanks

Subodh

Any way to show / hide sheets
 
On May 6, 8:34*pm, SteAXA wrote:
I need a way, when i open a workbook, to hide all sheets till the user enter
the correct password.
When the user enter the password i want be able to show all sheets.
Please, someone can help me?
Thanks

I tried the following to make a sheet hidden
Try same with some modifications for your need
But i think u must make at least one sheet active
cannot hide all sheets
U can do that for a extra blank sheet
IF u need to hide all the sheets then u can set the password to open
THat will be useful then VBA code
The following code should be in the workbook.

Dim sLast As Object



Private Sub Workbook_Open()

'Ensure Sheet1 is not the active sheet upon opening.

If Sheet1.Name = ActiveSheet.Name Then Sheet2.Select

End Sub



Private Sub Workbook_SheetActivate(ByVal Sh As Object)

pwd = Sheet1.Range("a2").Text 'this is the password to open the file

Dim strPass As String

Dim lCount As Long



If Sh.CodeName < "Sheet1" Then

'Set sLast variable to the last active sheet _

' This is then used to return the user to the _

' last sheet they were on if password is not known _

' or they Cancel.

Set sLast = Sh



Else

'Hide Columns

Sheet1.Columns.Hidden = True

'Allow 3 attempts at password

For lCount = 1 To 3

strPass = InputBox(Prompt:="Password Please" &
vbNewLine _
& "Password is case sensitive. Attempt " & lCount & "
of 3.", Title:="PASSWORD REQUIRED")

If strPass = vbNullString Then 'Cancelled

sLast.Select

Exit Sub

ElseIf strPass < pwd Then 'InCorrect password

MsgBox "Password incorrect", vbCritical,
"Subodh"

Else 'Correct Password

Exit For

End If

Next lCount



If lCount = 4 Then 'They use up their 3 attempts

sLast.Select

Exit Sub

Else 'Allow viewing

Sheet1.Columns.Hidden = False

End If

End If

End Sub


SteAXA

Any way to show / hide sheets
 
I forget to say you that i read the password from a database and the password
depends on the user name.
So, i can't use the excel password (tools/options) for protect workbook.

SteAXA

Any way to show / hide sheets
 
No need answer i found it. Sometimes i forget that the macro can help me!
Excuse me for the post!

"SteAXA" wrote:

I need a way, when i open a workbook, to hide all sheets till the user enter
the correct password.
When the user enter the password i want be able to show all sheets.
Please, someone can help me?
Thanks



All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com