Unprotect workbook, allow repeat password

SueBK

Board Regular
Joined
Aug 12, 2014
Messages
114
In one of my macros, I unprotect a shared workbook. I haven't programmed the password into the code. I admit, mainly because I was having problems with it, and decided that entering it manually wasn't such huge deal LOL. The line of code I'm using is simple "ActiveWorkbook.UnprotectSharing".

This morning I typed in the wrong password and got an end/debug error message. Ideally, I'd like to either have the password as part of the code, or allow for repeat entry of the password if it's incorrect. Or, failing either of those, an end macro message (which would be messy because I end up with a partly created backup file).
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Have you tried declaring a password as a constant?
Code:
Public Const pword As String = "MyPassword"  'Place at top of Module before Subrotine(s)

..
..
ActiveSheet.Unprotect Password:=pword
 
Upvote 0
I did try that. But because tracked changes are turned on it wants a yes/no response. I tried turning off the notification, but it didn't like that. I'd rather the user enter a password AND choose the yes/no, than just be faced with a warning message. Ideally, I'd like no warning message :)

My ultimate goal would be to allow a wrong password at least twice OR completely automate the process.
 
Upvote 0
You could use an "On Error Resume Next" before the unprotect to stop the error message then test if the Sheet is still protected (ActiveSheet.ProtectContents=True) to see whether the password was correct.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,055
Latest member
excelhelp12345

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