LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet Password


Hello,

I want to work on Sheet`s Protection.
I've got a very nice Sheet protection code given by some Excel expert
but it works only on a single sheet. I want to use it for multipl
worksheets. Can this code be changed to be used for multiple Shee
protection?


Dim LastActiveSheet As Worksheet


Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Not Sh Is Sheets("Locked") Then
Application.ScreenUpdating = False
Set LastActiveSheet = Sh
End If
End Sub


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh Is Sheets("Locked") Then
Sh.Visible = True
With Application
.EnableEvents = False
LastActiveSheet.Activate
.EnableEvents = True
End With
PromptForPassword
End If
End Sub


Sub PromptForPassword()
Dim UserInput As Variant
Const PWord1 As String = "abc"
Const PWord2 As String = "xyz"
Const Msg1 As String = "Sheet Locked For Viewing !" & vbNewLine _
& vbNewLine & "Enter Password To Unlock."
Const Msg2 As String = "Wrong Password !"

With Application
Do
UserInput = .InputBox(Msg1)
Select Case UserInput
Case Is = False ' if user cancells don't activat
sheet
Exit Do
Case Is = PWord1, PWord2 ' if password correc
activate sheet4
Set LastActiveSheet = Sheets("Locked")
Exit Do
Case Else 'if wrong password give user another try
UserDecision = MsgBox(Msg2, vbRetryCancel): Beep
End Select
Loop Until UserDecision = vbCancel

Sheets("Locked").Visible = True
.EnableEvents = False
LastActiveSheet.Activate
.EnableEvents = True
End With
End Sub


Thank you.
Regards,

Fara

--
Fara
-----------------------------------------------------------------------
Farah's Profile: http://www.excelforum.com/member.php...fo&userid=2777
View this thread: http://www.excelforum.com/showthread.php?threadid=47309

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password for cells and Password for sheet Emece Excel Discussion (Misc queries) 2 November 11th 09 03:23 AM
Password on a sheet wx4usa Excel Discussion (Misc queries) 1 July 23rd 07 08:17 PM
Protect Sheet with password through VBA bill_morgan_3333 Excel Programming 2 December 24th 04 04:03 AM
Protecting Sheet with Password halem2[_20_] Excel Programming 3 September 17th 04 01:58 AM
VBa, Password protected sheet fails to get unprotected with the same password Hans Rattink Excel Programming 3 July 28th 03 02:30 PM


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"