One way is to use the following code for Workbook Open Event.
The attached workbook contains a Sheet named Activation where A1 contains the Activation Key ("abab") for an example.
If the user provides this Activation Key, user won't get any prompt for trial period.
In the code the expiry date is set to "4/24/2016" so the user will have his/her last attempt to input an Activation Key on "4/24/2016" and after that date user won't be able to open the workbook.
Const exDate As String = "4/24/2016"
Private Sub Workbook_Open()
Dim akey
Dim vUser As String
'Disable the Ctrl+Break
Application.EnableCancelKey = xlDisabled
'Make sure that only one user can use this workbook
'In this case if the user is sktneer, workbook will be opened else application will be closed immediately
If Environ("UserName") <> "sktneer" Then Application.Quit
'Checking if the B1 on Activation Sheet contains the activation key which already exists in A1 on this sheet
'And if the Activation key isn't found in B1 or it is not equal to the Activation key in A1, the code will ask to input the Activation key
If Sheets("Activation").Range("B1").Value <> Sheets("Activation").Range("A1").Value Then
'if today's date is after the expiry date, the application will quit
If Date > CDate(exDate) Then Application.Quit
'User will be informed that how many days are left in trial period
MsgBox CDate(exDate) - Date & " day(s) is/are left in 30 day's trial period.", vbExclamation, "Day's Left!"
'Prompt to input the Activation key
akey = InputBox("Please input the Activation Key if you have one or click Cancel to continue.", "Activation Key Required!")
Sheets("Activation").Range("B1").Value = akey
'Now the code checks whether the Activation key provided is equal to pre-existing Activation key in cell A1 on Activation Sheet
If Sheets("Activation").Range("A1").Value = akey Then Exit Sub
'And if the today's date is greater than the date, application will quit after prompting the user.
If Date = CDate(exDate) Then
MsgBox "Your trial period is over.", vbCritical, "Thanks for using the Program!"
ThisWorkbook.Save
Application.Quit
End If
End If
End Sub
See if this is something you can work with.
Bookmarks