Date Expire and Password Protect Your Excel Project
- 3 Comment
When building your Excel projects, you may want to demo a trial version of the work you have completed without giving full access to the working program. There are a couple things you can do to the project to make it difficult to access the vba code you have created. In addition to that, we’ll look at how to add vba code to disable the project from opening.
Adding Expiration Code to the Auto_Open Macro
The goal of the code below is to prevent the workbook from opening if it has exceeded the specified date that you set. When the project opens, it will check today’s date against the expiration date and immediately close the program (Code below).
Dim ExpirationDate As Date
ExpirationDate = DateSerial(2011, 6, 10)
If Now() >= ExpirationDate Then
MsgBox “Trial Period ended on ” & CStr(ExpirationDate) & “.”
Further Protection of Your Excel Project
If the end user is savvy enough to open the project without running the auto_open macro, you have two more things you can do to help protect your work.
- Add the same code above (ExpirationCode) to the other subroutines in your project, so that it checks the expiration dates first.
- Add a password to the vba project, so that the code can’t be easily viewed or edited unless you know that password. To add a password to your vba project, right click on the module and select “VBAProject Properties…”. Select the “Protection” tab, click “Lock project for viewing” and then add your password to password protect to vba module. Remember to write you password down so you can later access your project. To disable the project, go back into the project and remove the password in the same manner.
Again, none of these methods is fool-proof against someone that really wants access to the files you are protecting. They are, however, a good deterrent to protecting your work and is a good starting place to let people know that the software is not yet available for distribution. If you need to open the workbook without running the expiration date code, hold down the shift key while opening the workbook.