Unprotect strange behaviour

VBAmateure

New Member
Joined
May 13, 2016
Messages
2
Hi to MrExcel staff and users,
As my username states, I am not a profesional programmer but rather a VBA amateure so - be gentle
:)

I have been struggling with a protection issue in an Excel VBA project I am doing and just can't seem to figure out what the heck is going on in my file.
The project is quite large so it will not be possible (nor necessary) to post all the code, the problem though, is quite simple:

As my project opens the user is prompted to enter a client name or an admin/power user password.
The Workbook and its main Worksheet are then unprotected accordingly with a pre-determined password (an admin will have everything unlockked, visible and editable while a power user may edit some specific ranges).

So far so good - everything works perfectly.

A certain macro in the project saves the file after some data is updated and also exports it to a new wb (which is then closed).
After that the Workbook_Open sub is triggred and the user must, again, enter a client name or an admin/power user password.
However, this second time, for a reason I just can't seem to figure out, both the Workbook and the Worksheet are not being unprotected.
The sub is the exact one that functions when the file is opened and I have verified that the correct password is used and that the unprotect functions are actually triggred but somehow everything remains blocked.
A manual unprotect, using the same password, works but I just can't understand why the code would it work the 1st time but not the 2nd.

Any ideas ?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
you need to look at what is the active workbook, it could be the focus is still on the one you just saved off and that why the code dosen't work as intended
 
Upvote 0
Hi mole999,
First of all, thanks for your time and attention in answering my question.
Your suggestion, though logical, is not the case as the newly created workbook is saved and then immediately closed, thus, the focus passes automatically to the only open workbook available which is This.Workbook.
Any other ideas someone ?
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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