Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Very new to VB. Have managed to paste this code into a workbook:
Option Explicit Private Sub Workbook_Open() Worksheets("Sheet1").Activate End Sub Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Dim ans Dim sh2 As Worksheet Application.EnableEvents = False If ActiveSheet.Name < "Sheet1" Then Set sh2 = ActiveSheet Sh.Activate Application.ScreenUpdating = False ans = Application.InputBox("Supply password") If ans < False Then If ans = "password" Then sh2.Activate End If End If End If Application.ScreenUpdating = True Application.EnableEvents = True End Sub It works great, but would like to modify it so that I only need to enter the password once to gain access to all worksheets, not each time I change worksheets. Much appreciated, rob |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Create a module level variable like Dim PasswordOK As Boolean. Set this to
True when the password is correctly entered. Then modify your code to check this variable and run only is it is False. -- Jim "rob" wrote in message ... | Very new to VB. Have managed to paste this code into a workbook: | | Option Explicit | | Private Sub Workbook_Open() | Worksheets("Sheet1").Activate | End Sub | | Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) | Dim ans | Dim sh2 As Worksheet | Application.EnableEvents = False | If ActiveSheet.Name < "Sheet1" Then | Set sh2 = ActiveSheet | Sh.Activate | Application.ScreenUpdating = False | ans = Application.InputBox("Supply password") | If ans < False Then | If ans = "password" Then | sh2.Activate | End If | End If | End If | Application.ScreenUpdating = True | Application.EnableEvents = True | End Sub | | It works great, but would like to modify it so that I only need to enter the | password once to gain access to all worksheets, not each time I change | worksheets. | | Much appreciated, | rob | |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using VB to password protect, but sheet remains visible | Excel Discussion (Misc queries) | |||
Password Required to View\edit a Sheet in a Workbook with Many She | Excel Discussion (Misc queries) | |||
Protect Workbook vs Worksheet?? | Excel Worksheet Functions | |||
Protect Workbook | Excel Discussion (Misc queries) | |||
Forgot My Workbook Password | Excel Discussion (Misc queries) |