Home |
Search |
Today's Posts |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You check to see if the workbook is unprotected. I was checking to see if there
were any errors by looking at mystr (mystr="" meant no errors). Maybe something like this... If mystr < "" then Me.Label1.Caption = myStr else Unload Me end if Tanya wrote: Hi Dave That makes sence and works as you said it would, thank you. However, there is no error message now when the password is incorrect. Below is the code at present - you will notice that I have commented out the label "": Option Explicit Private Sub CommandButton1_Click() Dim ws As Worksheet Dim eCtr As Long Dim wbUnprotected As Boolean Dim myStr As String Dim myPwd As String Application.ScreenUpdating = False myPwd = Me.txtUnprotect.Value eCtr = 0 For Each ws In ActiveWorkbook.Worksheets If ws.ProtectContents = True _ Or ws.ProtectDrawingObjects = True _ Or ws.ProtectScenarios = True Then On Error Resume Next ws.Unprotect Password:=myPwd If Err.Number < 0 Then eCtr = eCtr + 1 Err.Clear End If On Error GoTo 0 End If Next ws wbUnprotected = True If ActiveWorkbook.ProtectStructure = True _ Or ActiveWorkbook.ProtectWindows = True Then On Error Resume Next ActiveWorkbook.Unprotect Password:=myPwd If Err.Number < 0 Then wbUnprotected = False Err.Clear End If On Error GoTo 0 End If myStr = "" If wbUnprotected = False Then myStr = "Workbook Not Unprotected" End If If eCtr 0 Then If myStr < "" Then myStr = myStr & vbLf End If myStr = myStr & eCtr & " worksheets not unprotected!" End If 'If wbUnprotected = False Then 'Me.Label1.Caption = myStr 'Application.ScreenUpdating = True 'Me.Label1.Caption = "Administrator Only" 'txtUnprotect = "" 'End If If wbUnprotected = True Then Unload Me Worksheets("Admin").Select Range("A1").Select ActiveWindow.DisplayWorkbookTabs = True End If End Sub Private Sub txtUnprotect_Change() Me.CommandButton2.Enabled = CBool(Len(Me.txtUnprotect.Value) 0) End Sub Private Sub UserForm_Initialize() Me.Caption = "Enter Administrator Password" With Me.CommandButton2 .Caption = "Cancel" .Cancel = True .Enabled = False End With With Me.CommandButton1 .Caption = "OK" .Default = True .Enabled = True End With With Me.txtUnprotect .SetFocus .PasswordChar = "*" End With Me.Label1.Caption = "" End Sub Private Sub CommandButton2_Click() Unload Me End Sub Kind Regards Tanya -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
vba-password prompt on close | Excel Programming | |||
Excel add-in password prompt and Act! | Excel Programming | |||
prompt for password only once | Excel Programming | |||
Password Prompt | Excel Discussion (Misc queries) | |||
Password Prompt | Excel Discussion (Misc queries) |