I have login code that includes a password expiry date on first opening the workbook:
Private Sub cmdLogin_Click()
Dim user As String
Dim password As String
user = Me.txtUserID.Value
password = Me.txtPassword.Value
If [ISREF('ExpiryDate'!A1)] Then
If Date > Sheets("ExpiryDate").[A1] Then
MsgBox "This Trial version has now expired and the Workbook will close."
ActiveWorkbook.Close SaveChanges:=False
Else: MsgBox "This is a trial version and will expire on " & Sheets("ExpiryDate").[A1]
End If
Else
Worksheets.Add.Name = "ExpiryDate"
Sheets("ExpiryDate").[A1] = Date + 8
Sheets("ExpiryDate").Visible = False
MsgBox "This is a trial version and will expire on " & Sheets("ExpiryDate").[A1]
End If
I want to include code that deletes specific sheets when the Expiry date has passed. At the moment I have code in the Workbook bu this does not seem to work:
Private Sub Workbook_Delete_Sheets()
Dim oneSheet As Worksheet
Dim workingNames As Variant, oneName As String
Dim lastDay As Date
lastDay = Sheets("ExpiryDate").[A1]
Select Case Date
Case Is < lastDay
Rem OK
GoSub HideHidden
Case Is = lastDay
Rem warning
MsgBox "This is the last day that you can use this worksheet"
GoSub HideHidden
Case Else
Rem delete stuff
GoSub KillSheets
End Select
Exit Sub
KillSheets:
ThisWorkbook.Sheets("Getting Started").Visible = xlSheetVisible
Application.DisplayAlerts = False
For Each oneSheet In ThisWorkbook.Sheets
If oneSheet.Name <> "Getting Started" Then
oneSheet.Visible = xlSheetHidden
oneSheet.Delete
End If
Next oneSheet
Application.DisplayAlerts = True
ThisWorkbook.Save
Return
HideHidden:
For Each oneSheet In ThisWorkbook.Sheets
If oneSheet.Name <> "Getting Started" Then
oneSheet.Visible = xlSheetVisible
End If
Next oneSheet
ThisWorkbook.Sheets("Getting Started").Visible = xlSheetVeryHidden
Return
End Sub
Anyone help here? I still find vba a bit of a challenge.
Private Sub cmdLogin_Click()
Dim user As String
Dim password As String
user = Me.txtUserID.Value
password = Me.txtPassword.Value
If [ISREF('ExpiryDate'!A1)] Then
If Date > Sheets("ExpiryDate").[A1] Then
MsgBox "This Trial version has now expired and the Workbook will close."
ActiveWorkbook.Close SaveChanges:=False
Else: MsgBox "This is a trial version and will expire on " & Sheets("ExpiryDate").[A1]
End If
Else
Worksheets.Add.Name = "ExpiryDate"
Sheets("ExpiryDate").[A1] = Date + 8
Sheets("ExpiryDate").Visible = False
MsgBox "This is a trial version and will expire on " & Sheets("ExpiryDate").[A1]
End If
I want to include code that deletes specific sheets when the Expiry date has passed. At the moment I have code in the Workbook bu this does not seem to work:
Private Sub Workbook_Delete_Sheets()
Dim oneSheet As Worksheet
Dim workingNames As Variant, oneName As String
Dim lastDay As Date
lastDay = Sheets("ExpiryDate").[A1]
Select Case Date
Case Is < lastDay
Rem OK
GoSub HideHidden
Case Is = lastDay
Rem warning
MsgBox "This is the last day that you can use this worksheet"
GoSub HideHidden
Case Else
Rem delete stuff
GoSub KillSheets
End Select
Exit Sub
KillSheets:
ThisWorkbook.Sheets("Getting Started").Visible = xlSheetVisible
Application.DisplayAlerts = False
For Each oneSheet In ThisWorkbook.Sheets
If oneSheet.Name <> "Getting Started" Then
oneSheet.Visible = xlSheetHidden
oneSheet.Delete
End If
Next oneSheet
Application.DisplayAlerts = True
ThisWorkbook.Save
Return
HideHidden:
For Each oneSheet In ThisWorkbook.Sheets
If oneSheet.Name <> "Getting Started" Then
oneSheet.Visible = xlSheetVisible
End If
Next oneSheet
ThisWorkbook.Sheets("Getting Started").Visible = xlSheetVeryHidden
Return
End Sub
Anyone help here? I still find vba a bit of a challenge.