Dear Experts,
It is third time when the workbook automatically set the password to protect Workbook structure i do not why it is happening. Please help to resolve the issue.
Dear Experts,
It is third time when the workbook automatically set the password to protect Workbook structure i do not why it is happening. Please help to resolve the issue.
Why don't you simply try to understand my working example I keep giving you? You can always ask for questions about the code
I was trying to understand your example and add the code to Userform2 for changing the password but could not. Then i thought that and probably if i keep asking questions then you will be annoyed. Thats why i used this one.
Just ask questions about what you don't understand
I have changed the Userform which is attached below and also trying to change your given code but could not.
I was trying to create a loop if i open the sheet with the username a button is added on each user sheet with named reset password.
When user is change their password then concern user password should be change in admin sheet.
user : shoaib.ali
Pass : shoaib
Don't hide the application when developing code. When an error occurs you end up with an invisible instance of Excel running.
There's no code that I can see to add buttons. Why do you want to add buttons?
The only code that works efficiently in the workbook is mine and you aren't using it. Your code to change the password only works on one cell!
Why have you changed the layout of the table that stores the passwords?
Q. Don't hide the application when developing code. When an error occurs you end up with an invisible instance of Excel running.
I dont know how.
Q. There's no code that I can see to add buttons. Why do you want to add buttons?
I have a sheet where someone has used this loop.
Q. The only code that works efficiently in the workbook is mine and you aren't using it. Your code to change the password only works on one cell!
I know your code is perfect one but i dont know how the code will change password of users and automatically will be add in admin sheet under username.
Q. Why have you changed the layout of the table that stores the passwords?
Because i was trying to create loop as attached sheet has created.
User - Admin
Password - Chuckles1
Unlock Sheet - entity
Unlock VBA - pbarratt6344
Where did you get that workbook from? It's VBA is password protected and it looks like it shouldn't really be posted on public forum
I have got this from Ozgrid.
I also try to learn form other people worksheets.
All passwords are mentioned in previous comments.
User - Admin
Password - Chuckles1
Unlock Sheet - entity
Unlock VBA - pbarratt6344
Your previous post contains a workbook that has it's code protected.
I'm busy at the moment but I'm looking at your userforms.
Ok i will wait for resolution.
It will probably be in the morning
I will be grateful to you if could add comments to understand the code.
I am doing
See if this is what you are trying for.
Below error is occurring while login.
Replace code with this.
Private Sub CommandButton1_Click()
Dim oWs As Worksheet
Dim cnt As Integer
Dim sht As String ''///If an error occurs make sure that Excel application is visible
On Error GoTo exit_proc
With Me.ComboBox1
''///don't run code if no selection made
If .ListIndex < 0 Then Exit Sub
If Me.tbxPassWord.Value = .List(.ListIndex, 1) Then
MsgBox "Welcome " & .Value
''/// this will unhide Excel
Application.Visible = True
''/// unprotect the workbook
ThisWorkbook.Unprotect ("password")
''/// if the user is admin(Shoaib) then show all sheets
If .ListIndex = 0 Then
For Each oWs In ThisWorkbook.Worksheets
oWs.Visible = xlSheetVisible
Next oWs
Else
''/// this line gets the sheet name by removing the . in the user name displayed in the combobox and converts it to Proper case
sht = StrConv(Replace(.Value, ".", " "), vbProperCase)
''/// unhide relevant sheet
Worksheets(sht).Visible = xlSheetVisible
''/// hide all sheets except admin
HideAllSheets sht
End If
''/// check number of attempts
Else: cnt = cnt + 1
''/// check if less than 3 attempts
If cnt < 3 Then
MsgBox "Wrong Password", vbCritical, "Try again"
''///if third att
Else: MsgBox "You have entered an incorrect password 3 times.The workbook will now close.", vbCritical, "Contact admin"
ThisWorkbook.Close False
End If
End If
End With
Exit Sub
exit_proc:
Application.Visible = True
ThisWorkbook.Close False
End Sub
Display More
I thought I had corrected that before uploading.
Thank you so much i will definitely learn from your codes.
Pleased it works.
Don’t have an account yet? Register yourself now and be a part of our community!