Unprotect strange behaviour


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


Oct 23, 2004
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


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

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...