If file isn't Excel AddIn, execution of code depends on "Enable macros" option and macros level.
So, the code will never execute, if macro level is set to "high" or user choose "Disable macro" button.
Option Explicit
Sub TestExpDate()
Dim retVal As Variant
retVal = GetExpiredDate()
If retVal = 0 Then retVal = SetExpiredDate()
If retVal > Date Then
MsgBox DateDiff("d", Date, retVal) & " days left!", vbInformation, "Information..."
Else
MsgBox "The end!", vbInformation, "Information..."
End If
End Sub
Function SetExpiredDate() As Variant
Dim retVal As Variant, dp As DocumentProperty, dDate As Date
On Error GoTo Err_SetExpiredDate
retVal = 0
dDate = DateAdd("d", 30, Date)
DeleteExpDate
Set dp = ThisWorkbook.CustomDocumentProperties.Add(Name:="ExpDate", LinkToContent:=False, Type:=msoPropertyTypeDate, Value:=dDate, LinkSource:=False)
retVal = dp.Value
Exit_SetExpiredDate:
On Error Resume Next
Set dp = Nothing
SetExpiredDate = retVal
Exit Function
Err_SetExpiredDate:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_SetExpiredDate
End Function
Function GetExpiredDate() As Variant
Dim retVal As Variant, dp As DocumentProperty
On Error GoTo Err_GetExpiredDate
retVal = 0
Set dp = ThisWorkbook.CustomDocumentProperties("ExpDate")
retVal = dp.Value
Exit_GetExpiredDate:
On Error Resume Next
Set dp = Nothing
GetExpiredDate = retVal
Exit Function
Err_GetExpiredDate:
Select Case Err.Number
Case 9, 5
retVal = 0
Case Else
MsgBox Err.Description, vbExclamation, Err.Number
End Select
Resume Exit_GetExpiredDate
End Function
Sub DeleteExpDate()
On Error Resume Next
ThisWorkbook.CustomDocumentProperties("ExpDate").Delete
End Sub
You can use some trick:
1) hide your "working" sheet,
2) add empty sheet and place information: "To use this file, you must enable macros.",
3) add code to make your sheet visible everytime when user open file until date is < exp. date.