LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Prompt for password

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
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
vba-password prompt on close kikde Excel Programming 3 November 15th 05 01:38 PM
Excel add-in password prompt and Act! Bob Flanagan Excel Programming 0 August 12th 05 09:03 PM
prompt for password only once Mike Boynton via OfficeKB.com Excel Programming 4 May 27th 05 01:34 PM
Password Prompt Noel Excel Discussion (Misc queries) 0 May 18th 05 07:42 PM
Password Prompt LuhElle Excel Discussion (Misc queries) 1 March 8th 05 11:11 PM


All times are GMT +1. The time now is 03:13 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"