ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   re Password Change again (https://www.excelbanter.com/excel-programming/285979-re-password-change-again.html)

libby

re Password Change again
 
Hi John

yes that was just a typo before.
I've copied my code below the message I get is
Method Unprotect of object worksheet failed.
txtOld is the old password entered into a textbox on the
form.

Private Sub cmdChange_Click()
If MsgBox("Changing passwords will result in the current
data being lost" & vbNewLine & _
vbNewLine & "Do you want to continue?", vbYesNo) = vbYes
Then
Sheet1.unprotect PASSWORD:=Sheet3.Range("H65536").End
(xlUp).Value
ThisWorkbook.unprotect PASSWORD:=Sheet3.Range("E65536").End
(xlUp).Value
If optMan = True Then 'manager authorisation password
Select Case txtOld.Text
Case Sheet3.Range("b65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet3.Range("b65536").End(xlUp).Value =
TextBox1.Text
Call save
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

ElseIf optWB = True Then 'workbook password
Select Case txtOld.Text
Case Sheet3.Range("e65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet3.Range("e65536").End(xlUp).Value =
TextBox1.Text
Call save
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

ElseIf optWS = True Then
Select Case txtOld.Text
Case Sheet3.Range("h65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet1.unprotect PASSWORD:=txtOld.Text
Sheet3.Range("h65536").End(xlUp).Value =
TextBox1.Text
Call save
Unload Me
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

End If
End If
End Sub

Sub save()
With Sheet1
.Range
("C16,D2:F2,D6:F6,D8:F8,D18:G21,F24:F28").ClearCon tents
.TextBox1.Enabled = True
.TextBox2.Enabled = True
.txtSpecify.Enabled = True
.TextBox1 = ""
.TextBox2 = ""
.txtSpecify = ""
.TextBox1.Enabled = False
.TextBox2.Enabled = False
.txtSpecify.Enabled = False
.cmdChange.Enabled = False
.CommandButton1.BackColor = vbRed
.CommandButton1.Caption = "Ï"
End With

ThisWorkbook.save
ThisWorkbook.Protect PASSWORD:=Sheet3.Range("e65536").End
(xlUp).Value, structu=True
Sheet1.Protect PASSWORD:=Sheet3.Range("h65536").End
(xlUp).Value, USERINTERFACEONLY:=True
End Sub

John Wilson

re Password Change again
 
Libby,

Please try to continue in the same thread and not start a new one.
It helps others (who may be able to help you) follow what's
transpired to get you to your goal.

If possible, can you send the workbook directly to me and
I'll take a look at it.


John


"Libby" wrote in message
...
Hi John

yes that was just a typo before.
I've copied my code below the message I get is
Method Unprotect of object worksheet failed.
txtOld is the old password entered into a textbox on the
form.

Private Sub cmdChange_Click()
If MsgBox("Changing passwords will result in the current
data being lost" & vbNewLine & _
vbNewLine & "Do you want to continue?", vbYesNo) = vbYes
Then
Sheet1.unprotect PASSWORD:=Sheet3.Range("H65536").End
(xlUp).Value
ThisWorkbook.unprotect PASSWORD:=Sheet3.Range("E65536").End
(xlUp).Value
If optMan = True Then 'manager authorisation password
Select Case txtOld.Text
Case Sheet3.Range("b65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet3.Range("b65536").End(xlUp).Value =
TextBox1.Text
Call save
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

ElseIf optWB = True Then 'workbook password
Select Case txtOld.Text
Case Sheet3.Range("e65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet3.Range("e65536").End(xlUp).Value =
TextBox1.Text
Call save
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

ElseIf optWS = True Then
Select Case txtOld.Text
Case Sheet3.Range("h65536").End(xlUp).Value
If TextBox1.Text < TextBox2.Text Then
MsgBox "Passwords are not the same!" & vbNewLine
& "Please try again", vbCritical
TextBox1 = ""
TextBox2 = ""
TextBox1.SetFocus
Else
Sheet1.unprotect PASSWORD:=txtOld.Text
Sheet3.Range("h65536").End(xlUp).Value =
TextBox1.Text
Call save
Unload Me
End If
Case Else
MsgBox "Invalid Password", vbCritical
txtOld = ""
txtOld.SetFocus
End Select

End If
End If
End Sub

Sub save()
With Sheet1
.Range
("C16,D2:F2,D6:F6,D8:F8,D18:G21,F24:F28").ClearCon tents
.TextBox1.Enabled = True
.TextBox2.Enabled = True
.txtSpecify.Enabled = True
.TextBox1 = ""
.TextBox2 = ""
.txtSpecify = ""
.TextBox1.Enabled = False
.TextBox2.Enabled = False
.txtSpecify.Enabled = False
.cmdChange.Enabled = False
.CommandButton1.BackColor = vbRed
.CommandButton1.Caption = "Ï"
End With

ThisWorkbook.save
ThisWorkbook.Protect PASSWORD:=Sheet3.Range("e65536").End
(xlUp).Value, structu=True
Sheet1.Protect PASSWORD:=Sheet3.Range("h65536").End
(xlUp).Value, USERINTERFACEONLY:=True
End Sub




All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com