April 26, 2018
I have a WorkBook for daily reporting, Daily Report ver.5.xlsm
I would like to ad some code to WorkBook_open that checks the name of the workbook upon opening and see if the File name has been change.
So if the WorkBook file name is not Daily Report ver.5.xlsm then a Inputbox pops up and asks for a Password to open.
If password is not correct then Application.quit
This is to prevent users from copying and renaming the workbork so nobody knows what workbook to use.
Can somebody help me with this please?
October 5, 2010
It is possible to do something like this but there are a few issues with this approach.
It relies on the person opening the workbook to have VBA enabled or your code won't run. If they have disabled all macros, or choose not to enable macros when they open the workbook, they can open the workbook anyway.
If this happens you can do things like protect the sheets or make the sheets Very Hidden to try to prevent them being edited. But a determined user could still get past this.
If VBA is disabled, and you don't protect the VBA modules by locking them for viewing then someone just needs to open the VBA editor and they can see the password required to open the workbook. This is assuming that the password is stored in the VBA code, as in my sample workbook.
It's possible to get around password protection like that too though.
With the above approach, if the filename has been changed, and someone enters the correct password, they will be able to open the workbook but it'll be a copy with a different name. So that doesn't achieve what you want?
If the the filename has changed then wouldn't you just want to close the workbook?