Fellow excel experts
Discussion
I have been working on a way of locking down an excel workbook to prevent users from making unauthorised changes - whilst leaving the ability to make authorised ones.
I have come up with a method - but would like some thoughts on whether it can be circumvented by a relatively lay person.
1. Workbook and all worksheets are protected with a password and I have security macros running. The macros cannot be interrupted by the users (e.g. enablecanclekey = false).
2. To ensure that the user enables macros when they open the workbook - I have hidden all sheets except a warning sheet (which tells them they cannot use the workbook without macros active). If the workbook is opened and macros are not activated - only the warning sheet is displayed. If the user enables macros, the warning sheet is hidden on-open and the normal worksheets are un-hidden. Since the workbook is password protected by default, manual un-hiding of worksheets should not be possible even if macros are not activated.
3. Once opened with macros running, I have macros that upon a change of cell selection, right click or activation/deactivation of a worksheet, a macro re-locks all worksheets and workbook with a new randomised password.
4. I randomise the password at each re-lock using the following method. I generate a random 10 digit number using the RND function. I multiply this number by the current time, then convert the result to a Hex string. This becomes the current password.
5. The current password is stored on a "very hidden" worksheet - and is updated every time I go through steps 3 and 4. This ensures that the password is never more than 1 event old before being reset and that even if the user somehow unlocks the worksheet/workbook, as soon as they trigger an event, the worksheet/workbook is relocked and the password reset. Even if the user could somehow unhide the sheet the current password is stored on - as soon as they deselect the sheet and go to another sheet to make a change - the sheets/workbook will be re-locked and the password re-randomised.
Can anyone see any issues/workarounds whereby the user could intentionally or unintentionally circumvent this?
I have come up with a method - but would like some thoughts on whether it can be circumvented by a relatively lay person.
1. Workbook and all worksheets are protected with a password and I have security macros running. The macros cannot be interrupted by the users (e.g. enablecanclekey = false).
2. To ensure that the user enables macros when they open the workbook - I have hidden all sheets except a warning sheet (which tells them they cannot use the workbook without macros active). If the workbook is opened and macros are not activated - only the warning sheet is displayed. If the user enables macros, the warning sheet is hidden on-open and the normal worksheets are un-hidden. Since the workbook is password protected by default, manual un-hiding of worksheets should not be possible even if macros are not activated.
3. Once opened with macros running, I have macros that upon a change of cell selection, right click or activation/deactivation of a worksheet, a macro re-locks all worksheets and workbook with a new randomised password.
4. I randomise the password at each re-lock using the following method. I generate a random 10 digit number using the RND function. I multiply this number by the current time, then convert the result to a Hex string. This becomes the current password.
5. The current password is stored on a "very hidden" worksheet - and is updated every time I go through steps 3 and 4. This ensures that the password is never more than 1 event old before being reset and that even if the user somehow unlocks the worksheet/workbook, as soon as they trigger an event, the worksheet/workbook is relocked and the password reset. Even if the user could somehow unhide the sheet the current password is stored on - as soon as they deselect the sheet and go to another sheet to make a change - the sheets/workbook will be re-locked and the password re-randomised.
Can anyone see any issues/workarounds whereby the user could intentionally or unintentionally circumvent this?
Were I to try to hack it, I'd probably make a personal.xlsb with a deliberately wrong workbook open event to throw an error at the right place, pop into debug and then use the immediate window to unveryhide everything and re-enable cancelkey while VBA is stopped. Havoc could then be wreaked.
But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"
It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.
But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"
It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.
So the macros are only there to unprotect the sheet and then lock it again?
Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?
Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.
Unless I've wildly misunderstood, I think you're really overcomplicating this
Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?
Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.
Unless I've wildly misunderstood, I think you're really overcomplicating this
davepoth said:
Were I to try to hack it, I'd probably make a personal.xlsb with a deliberately wrong workbook open event to throw an error at the right place, pop into debug and then use the immediate window to unveryhide everything and re-enable cancelkey while VBA is stopped. Havoc could then be wreaked.
But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"
It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.
I have error handlers which mean that it should not be possible to cause a break point in my code - any error will immediately hand off to the error handler - whose only function is to capture the error and display a pop up error. The error handlers themselves utilise "on error resume next" in them - so they should not cause a break point either.But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"
It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.
My VBA project is also password protected - so even if they can somehow get into the VB editor - they should not be able to view or modify code.
I know, in an ideal world, I shouldn't be using excel - but i'm trying to get the company to a better position than they are in now (unrestricted, unlocked and uncontrolled spreadsheets).
If I can at least put some controls around what they have - it's a start.
I suspect creating an xlsb with code designed specifically to cause a break point is a little beyond the capabilities of a lay person. I'm not trying to prevent hackers messing with this file - just 'normal users'.
Edited by Moonhawk on Wednesday 21st March 23:32
Doofus said:
So the macros are only there to unprotect the sheet and then lock it again?
Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?
Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.
Unless I've wildly misunderstood, I think you're really overcomplicating this
I'm using a randomised password - because a static password could at some point be guessed or inadvertently revealed.Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?
Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.
Unless I've wildly misunderstood, I think you're really overcomplicating this
By randomising the password with each event - I hopefully avoid the password getting out into the wild. The workbook essentially manages and protects the password itself.
I would of course have to use a static password for the VBA project - that is pretty much unavoidable - but it's one level of complexity further up the chain. Most 'normal' users won't even know about the VBA editor - let alone know enough about it to make it visible or start causing trouble within it - even if they did somehow know the password.
Moonhawk said:
I suspect creating an xlsb with code designed specifically to cause a break point is a little beyond the capabilities of a lay person. I'm not trying to prevent hackers messing with this file - just 'normal users'.
I dunno - even I can manage to write macros that are guaranteed to cause an error. 
Locking down spreadsheets hard like this (and I have tried something similar previously) can have some odd side effects, especially when there are other spreadsheets open. If any of those other spreadsheets have macros themselves (and it sounds like they might) they could well start interacting in strange ways.
If you don't want to jump to Access, what about using a form in Excel rather than a spreadsheet for the data entry?
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
Would the average lay person know enough about xml to be able to do that, make an incognito change to a specific entry in the workbook - then reinstate the workbook to a functional state - without breaking the workbook - and without anyone knowing?Edited by Moonhawk on Wednesday 21st March 23:43
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.
You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
Moonhawk said:
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
Would the average lay person know enough about xml to be able to do that, make an incognito change to a specific entry in the workbook - then reinstate the workbook to a functional state - without breaking the workbook - and without anyone knowing?Edited by Moonhawk on Wednesday 21st March 23:43

Mr Pointy said:
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.
You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
I dont think they will be able to crack the random password - that’s my point. A hard coded traditional password might get out in the open inadvertently - but having the workbook constantly randomise it would (in theory) reduce this risk.You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
As for me leaving/future maintenance - that’s not an issue. The VBA project password will still be available to suitably qualified and authorised individuals - and the radomisaton code can be disabled once you have unlocked the VBA project.
The workbook should only need unlocking if placed under change control.
How do you unlock it to make changes yourself? (Admin access.)
I had a little thing made so that the way to unlock it was to shift-click on the pi symbol that floated in the bottom right corner of the spreadsheet, and then required a password. The floating location was updated on a cell selection so it was always in the right place even for users with different sized monitors and so on.
I might have had a thing for Sandra Bullock in the 90s...
I had a little thing made so that the way to unlock it was to shift-click on the pi symbol that floated in the bottom right corner of the spreadsheet, and then required a password. The floating location was updated on a cell selection so it was always in the right place even for users with different sized monitors and so on.
I might have had a thing for Sandra Bullock in the 90s...
Moonhawk said:
Mr Pointy said:
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.
You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
I dont think they will be able to crack the random password - that’s my point. A hard coded traditional password might get out in the open inadvertently - but having the workbook constantly randomise it would (in theory) reduce this risk.You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
As for me leaving/future maintenance - that’s not an issue. The VBA project password will still be available to suitably qualified and authorised individuals - and the radomisaton code can be disabled once you have unlocked the VBA project.
The workbook should only need unlocking if placed under change control.
I've seen excel compilers used to secure spreadsheets in financial institutions, basically as a band-aid. The application had grown from a single user sheet to a departmental one so security hadn't been implemented at the server side.
I can't remember which products were used, but similar to these:
https://www.xlspadlock.com
http://doneex.com/how-to-compile-workbook/
I can't remember which products were used, but similar to these:
https://www.xlspadlock.com
http://doneex.com/how-to-compile-workbook/
Mr Pointy said:
I'm still struggling with the logic behind your plan. You say a hardcoded password could get out & then say the even more powerful VBA password is being made available. Why won't this get out in the same way that the other password might?
The worksheet and workbook level passwords would have to be hard coded into the VBA code - somebody could look over the devs shoulder and see them.That's not true of the VBA project level password.
louiebaby said:
How do you unlock it to make changes yourself? (Admin access.)
I'd unlock the VBA console using the VBA project password - then set a developer flag I have built into the code which would unlock the workbook and worksheets and disable password randomisation the next time the password reset code ran.SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
I have been thinking about this and it is surprisingly easy to modify data in an xlsx via this method (even a relatively lay person could do this as you are basically just text editing).To help guard against these types of changes - I could compile all of the data in each worksheet into a string, then generate a hash value based on this string. I could then concatenate these hash values and generate a new workbook level hash from it. I could then store this hash value on save.
On open - I can regenerate the workbook level hash and compare with the stored value. This would highlight any changes to the underlying data in the worksheet. If there is an issue - I could flag it.
Of course - somebody who knew what they were doing could also modify the stored hash value via the xml - but that would require a hell of a lot of effort as they would have to know exactly what data I have used to generate it, in exactly the right order. They would also need to know the hash algorithm I had used.
Edited by Moonhawk on Thursday 22 March 17:17
Moonhawk said:
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
I have been thinking about this and it is surprisingly easy to modify data in an xlsx via this method (even a relatively lay person could do this as you are basically just text editing).To help guard against these types of changes - I could compile all of the data in each worksheet into a string, then generate a hash value based on this string. I could then concatenate these hash values and generate a new workbook level hash from it. I could then store this hash value on save.
On open - I can regenerate the workbook level hash and compare with the stored value. This would highlight any changes to the underlying data in the worksheet. If there is an issue - I could flag it.
Of course - somebody who knew what they were doing could also modify the stored hash value via the xml - but that would require a hell of a lot of effort as they would have to know exactly what data I have used to generate it, in exactly the right order. They would also need to know the hash algorithm I had used.
Edited by Moonhawk on Thursday 22 March 17:17

Its not paranoia if they really are after you!
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



