See the attached file which I think does what you're asking for.
This goes in the Workbook_Open() event - there are two commented out lines which you should uncomment in the real code so that users cannot unhide the sheet that contains the expiry date and password.
Option Explicit
Public Sub Workbook_Open()
'check if an expiry date has been set - if not set to now + 8 months.
Dim wksHidden As Worksheet
Dim celDate As Range
Dim datExpiry As Date
Set wksHidden = ThisWorkbook.Worksheets("DateStore")
'wksHidden.Visible = xlSheetHidden
Set celDate = wksHidden.Range("A1")
If celDate.Value = Empty Then celDate.Value = DateAdd("m", 8, Now())
datExpiry = celDate.Value
If Now() > datExpiry Then Call Reset.Reset_Initialize
'wksHidden.Visible = xlSheetVeryHidden
End Sub
And this goes in the form object:
Option Explicit
Public Sub btnClose_Click()
Unload Me
End Sub
Public Sub btnReset_Click()
Dim strPW As String
Dim varMsg As Variant
strPW = Trim(Me.txtPassword)
If strPW = ThisWorkbook.Worksheets("DateStore").Range("B1").Value Then
ThisWorkbook.Worksheets("DateStore").Range("A1").Value = DateAdd("m", 8, Now())
varMsg = MsgBox("The file expiry date has been extended by 8 months and will now expire on " & Format(ThisWorkbook.Worksheets("DateStore").Range("A1").Value, "dd mmm yyyy"), vbInformation + vbOKOnly, "Code accepted")
Else
varMsg = MsgBox("You have entered an incorrect password and the expiry date will not be extended.", vbCritical + vbOKOnly, "Incorrect password")
End If
Call btnClose_Click
End Sub
Public Sub Reset_Initialize()
Dim strFilename As String
strFilename = Left(ActiveWorkbook.Name, (InStrRev(ActiveWorkbook.Name, ".", -1, vbTextCompare) - 1))
Me.Caption = strFilename & " File - Registration Key"
Me.Show
End Sub
Hope that helps. MM.
Bookmarks