Constantly Changing Password Macro

Vampirex

New Member
Joined
Aug 9, 2019
Messages
5
HI All,

Trying to design a Macro which will automatically unlock the workbook and do hide or unhide a Worksheet. What will trigger the Macro will be a value change in a cell. The problem is, the password is not constant. One week it will be one word and the next it will be something else. I have designed one where the password is the same all the time:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Me.Range("H1").Address Then
If Target.Value = "5" Then
ActiveWorkbook.Unprotect "password"
Sheets("W5").Visible=True
ActiveWorkbook.protect "password"
Else
ActiveWorkbook.Unprotect "password"
Sheets("W5").Visible=False
ActiveWorkbook.protect "password"
End if
End if
End Sub

I want so that whatever the workbook password that the user has used to protect the work book in the first place will remain the same. For example I have lock my workbook, but my password is "Excel 1". The following month I will change it to "Excel 2". I do not actually want to show the password in the Macro. Is there a macro for this?

Please can somebody help.

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If I understand what you want correctly you could have a input box where the user types in the password.

something like

Code:
Sub prosheet()
Dim pw As String
pw = InputBox("enter password")
ActiveWorkbook.Unprotect pw
Sheets("Sheet2").Visible = False
ActiveWorkbook.Protect pw

End Sub
 
Upvote 0
If I understand what you want correctly you could have a input box where the user types in the password.

something like

Code:
Sub prosheet()
Dim pw As String
pw = InputBox("enter password")
ActiveWorkbook.Unprotect pw
Sheets("Sheet2").Visible = False
ActiveWorkbook.Protect pw

End Sub

Hi Scott T,

Thank you for your reply.

I do not want to have a InputBox. The password is enter or created elsewhere. The password has already been set. The Macro I am looking for is for the Macro to Unlock using whatever the password is.

For Example I have locked the book using the password "Excel 1"
I have now changed one of the cells that would trigger the Macro. For Example, cell H1 I have changed from a 5 to a 4
I would like for the Macro to unlock the sheet and then make hide a worksheet and then lock itself up again with the same password. If I decide to change the password for some reason, the Macro should not be affected and should still work the same.

I hope this makes sense.

Thanks
 
Upvote 0
I do not want to have a InputBox. The password is enter or created elsewhere. The password has already been set. The Macro I am looking for is for the Macro to Unlock using whatever the password is.

You say you want to unlock whatever the password is but if is your real intention I think you will find this to be regarded as "cracking" which we are not allowed to discuss here -

You need to tell your code the password you have set but have rejected inputbox suggestion. You can pass it via a variable which can be declared as public so all codes can read it but you need a method to populate the variable - If not an inputbox, what other means would you consider?

Dave
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top