Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have the following code, thanks to this forum and some very helpful people and I have just noticed that when I run the by way of the first code below and select cancel, I am taken to the admin sheet which is what I would like to avoid. What code to I need to add so that if cancel is selected I am not taken to Admin Sheet? Private Sub CommandButton1_Click() 'Unprotect workbook UnProtect_Workbook 'Show Admin Sheet Sheets("Admin").Visible = True Sheets("Admin").Select End Sub Sub UnProtect_Workbook() 'Unprotect workbook Dim ws As Worksheet Dim myPwd As String Application.ScreenUpdating = False Set ws = Worksheets(1) On Error Resume Next Do myPwd = GetPassword ws.Unprotect Password:=myPwd If myPwd < "" Then If ws.ProtectContents Then MsgBox "Invalid password, try again", vbOKOnly + vbInformation, "Password input" End If End If Loop Until Not ws.ProtectContents Or myPwd = "" On Error GoTo 0 If myPwd < "" Then For Each ws In ActiveWorkbook.Worksheets If ws.ProtectContents = True Then ws.Unprotect Password:=myPwd End If Next ws ActiveWorkbook.Unprotect Password:=myPwd Application.ScreenUpdating = True End If End Sub Private Function GetPassword() As Variant GetPassword = InputBox(Prompt:="Please enter correct Password") End Function Thanks in advance Cheers Tanya |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Password security | Excel Worksheet Functions | |||
Security & password protection | Excel Discussion (Misc queries) | |||
Password security problem: view of the hiden worksheet in xlsm and xlsx file !? | Excel Programming | |||
password security with excel 2007 | Excel Programming | |||
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. | Excel Worksheet Functions |