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 ?
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
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
 

VBAmateure

New Member
Joined
May 13, 2016
Messages
2
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 ?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,877
Messages
5,574,771
Members
412,617
Latest member
mlharris
Top