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: 155
Default Problem with password security

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
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 security Blue Excel Worksheet Functions 1 May 20th 09 12:46 PM
Security & password protection ogerriz Excel Discussion (Misc queries) 1 April 16th 09 10:20 AM
Password security problem: view of the hiden worksheet in xlsm and xlsx file !? Ivan Excel Programming 2 December 3rd 07 11:20 AM
password security with excel 2007 alfredo Excel Programming 2 May 31st 07 01:11 AM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM


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

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

About Us

"It's about Microsoft Excel"