Selected Answer
Zacrock
I haven't done the check for expiry but the attached file will be saved and closed the first time you open it (and tell you). When re-opened, it will tell you the demo has expired.
It looks like there's only one worksheet but there's a second, Sheet2 ("Locked") which is VeryHidden (so can't be revealed if the user right-clicks on a tab and chooses Unhide). It can only be revealed using VBA.
As it leaves me, cell A1 of that contains FALSE- this gets tested in the open procedure below (I've added comments to help):
Private Sub Workbook_Open()
Dim Resp As Long
' check if the file has been locked already (in very hidden sheet2)
If Sheet2.Cells(1, 1) = False Then
' if not, set the locked flag cell
Sheet2.Cells(1, 1) = True
Resp = MsgBox("Demo expired; this file will be locked, saved and closed", vbExclamation)
If Resp = 1 Then
' do the lock procedure
' << call another procedure>>
' save the workbook
ThisWorkbook.Close Savechanges:=True
End If
Else
MsgBox "File locked- the demo period has expired"
End If
End Sub
When the file is re-opened (provided macros are enabled*), you'll get the locked message.
You can reset it by changing A1 back to FALSE then in VBA Explorer's Immediate window pasting:
Sheet2.Visible=True
and return. Change A1 then use:
Sheet2.Visible=xlSheetVeryHidden
to hide it again. You'll need to test then add your lock procedure where I've indicated (or before you tell the user!).
(* Look in the Tutorials section, I'm pretty sure there's a lesson on how to force a file to be opened with macros-enabled).
Hope this helps. If so, please remember to mark this Answer as Selected.