Private Sub Workbook_Open()
'Copy and paste this into the Microsoft Excel Objects-> "ThisWorkbook" tab
'You need to remove the apostrophe in the below comment before using if desired- it will hide excel when the code first runs
'and if the code runs correctly, will show excel. If you happen to have an issue (say expired workbook) while this is running,
'you can double click the workbook again and it will force it to show
'Hides application
'Application.Visible = False
'defines code strings
Dim edate As String
Dim d As String
Dim ExpirationDate As String
'sets the variables
'so in this code I used a hidden sheet called "Developer" to house the date of expiration for me, you will need to set
'"developer" to the name of your sheet
ExpirationDate = edate
d = Sheets("Developer").Range("B39") 'registration key - a "password" that I had in a cell - if the user input this password it would reset the expiration date
edate = Sheets("Developer").Range("E37") 'expiration date - a date in a cell for expiration
'code checks to see if today's date is valid compared to your pre-defined expiration, if yes, shows excel and selects sheet
'"xxx". Make sure to change the name of xxx to your desired sheet.
If ExpirationDate < Date Then
Application.Visible = True
Sheets("xxx").Select
End If
'this is where things are fun- I used "Developer" again as my sheet- so in "Developer", Cell C36 had a date. Cell D36 (not mentioned/needed here)
'had a number- this was the number of days after C36, for which the workbook was good, and then C36+D36=E37. E37 was the "expiration" of the workbook
'C36 was reset to today's date if the program was expired AND the user input the password you had typed in "B39"
Else: d = Application.InputBox("Your workbook date has expired. Please enter the registration key to renew your license.")
If d = CStr(Worksheets("Developer").Range("B39").Value) Then
Sheets("Developer").Range("C36") = Date
MsgBox "Welcome Back " & s, vbOKOnly, namer
End If
End If
End If
Application.Visible = True 'inserted just to check workbook
'Protects/Hides sheets on startup
End Sub