Delete sheets on password expiry

bptaw

Board Regular
Joined
Feb 27, 2017
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Don't include : oneSheet.Visible = xlSheetHidden ... maintain the sheet to be deleted as visible.

The sheet to be deleted ... is the tab name "oneSheet" ? If not, be certain to use it's name. Example : Sheets("oneSheet").Delete
 
Upvote 0
Hi

Ideas that you are trying to develop only work if users activate macros & even then, security in Excel is not that great & can be overcome.

Having said that & Just my personal view - If you are developing an application for distribution to third parties then do be mindful that whilst you own the copyright to it, users own the data they enter – anything you attempt to do to limit the use of the application during a trial period should not prevent users from accessing their data should they decide not to continue with it & most certainly, you should not delete it if this is your intention?

I would suggest that you consider amending your code to limiting access to various features which can be re-activated if needed.



Dave
 
Upvote 0
Don't include : oneSheet.Visible = xlSheetHidden ... maintain the sheet to be deleted as visible.

The sheet to be deleted ... is the tab name "oneSheet" ? If not, be certain to use it's name. Example : Sheets("oneSheet").Delete
Can I add this code underneath "MsgBox "This Trial version has now expired and the Workbook will close."?
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top