PC Review


Reply
Thread Tools Rate Thread

Any way to show / hide sheets

 
 
SteAXA
Guest
Posts: n/a
 
      6th May 2010
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
 
Reply With Quote
 
 
 
 
Subodh
Guest
Posts: n/a
 
      6th May 2010
On May 6, 8:34*pm, SteAXA <Ste...@discussions.microsoft.com> 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

 
Reply With Quote
 
SteAXA
Guest
Posts: n/a
 
      6th May 2010
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.
 
Reply With Quote
 
SteAXA
Guest
Posts: n/a
 
      6th May 2010
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide all sheets but selected sheets - an example aztecbrainsurgeon@yahoo.com Microsoft Excel Programming 1 7th Apr 2006 06:29 PM
Show / Hide Columns in multiple sheets Shadster Microsoft Excel Programming 2 27th Jun 2005 12:09 PM
Hide/show sheets by first part of sheet name Brentus Microsoft Excel Programming 2 15th Sep 2004 06:21 AM
Show Form, Hide all Sheets John Pierce Microsoft Excel Programming 2 10th Jun 2004 10:42 AM
show userform, hide sheets JR Microsoft Excel Programming 0 20th Jan 2004 01:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 PM.