Jun 12 2011

Date Expire and Password Protect Your Excel Project

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).


Sub Auto_Open()
End Sub

Sub ExpirationCode()
Dim ExpirationDate As Date

ExpirationDate = DateSerial(2011, 6, 10)

If Now() >= ExpirationDate Then
MsgBox “Trial Period ended on ” & CStr(ExpirationDate) & “.”
ThisWorkbook.Close savechanges:=False
End If
End Sub

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.

  1. Add the same code above (ExpirationCode) to the other subroutines in your project, so that it checks the expiration dates first.
  2. 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.

VBAProject Properties


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.

More Excel Tips

Did you find this post helpful? Try signing up for our free daily tips.

Enter your email address: 


Comments are closed.

Sign Up for Excel Hints

Free updates with Excel Hints, Tips & Tricks