Private Sub Workbook_Open()
If Date < [IV65536].Value Or Date > [IV65535].Value Then
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
ActiveSheet.Unprotect
Cells.Clear
Next ws
ActiveWorkbook.Close True
Else: [IV65536].Value = Date
End If
End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Secret Count Sheet For Counting Times Open
Sheets("Count").Visible = True
'If Sheets("Count").Range("A1")= 500 Then WorkBook Is Registered. Open Workbook
If Sheets("Count").Range("B1") = "Registered" Then
Sheets("Count").Range("A1") = 500
Run "UnLocked" 'GoTo Private Sub UnLocked
Exit Sub
End If
'If It Not Registered After 60 Openings Delete Important Sheets. Set As Many Times You Prefer.
If Sheets("Count").Range("A1") > 60 Then 'Set As Many Times You Prefer Here.
Run "LockAndDelete" 'GoTo Private Sub LockAndDelete
Exit Sub
End If
'After 30 Times Opening Ask For A Serial Number, in this ex: "SERIAL".
If Sheets("Count").Range("A1") > 30 Then 'Set As Many Times You Prefer Here.
Serial = InputBox("This Workbook is limited to be opened 30 times unregistered!" & Chr(13) & Chr(13) & _
"You have now opened this Workbook " & Sheets("Count").Range("A1") & " times!" & Chr(13) & Chr(13) & _
"If you open this Workbook more than 60 times it will be deleted!" & Chr(13) & Chr(13) & _
"Please enter your Serial Number!")
'If SERIAL Is Wrong Show Only Sheets("Sorry")
If Serial <> "SERIAL" Then 'Change Serial To hat You Prefer Here.
Run "WrongSerial" 'GoTo Private Sub WrongSerial
Exit Sub
Else
'If SERIAL Is Wrong Show Only Sheets("Sorry")
If Serial = "SERIAL" Then 'Change Serial To hat You Prefer Here.
Run "Registered" 'GoTo Private Sub Registered
Exit Sub
End If
End If
End If
Sheets("Data").Visible = True
Sheets("Data").Select
Sheets("Count").Range("A1") = Sheets("Count").Range("A1") + 1 'Count On Sheets("Count") + 1 Each Time Book Opens.
'Save Workbook To Prevent From Close Without Count
ActiveWorkbook.Save
Sheets("Sorry").Visible = xlVeryHidden
Sheets("Count").Visible = xlVeryHidden
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Sheets("Sorry").Visible = True
Sheets("Sorry").Select
Range("A1").Select
Sheets("Data").Visible = xlVeryHidden
Sheets("Count").Visible = xlVeryHidden
'Save Workbook To Prevent From Close Without Saving
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub
Private Sub Registered()
'If Sheets("Count").Range("A1")= 500 Then WorkBook Is Registered. Open Workbook
Sheets("Data").Visible = True
Sheets("Data").Select
Sheets("Count").Range("B1") = "Registered"
Sheets("Count").Range("A1") = 500
Sheets("Sorry").Visible = xlVeryHidden
Sheets("Count").Visible = xlVeryHidden
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Thank You for register this product!"
End Sub
Private Sub Unlocked()
'If Right Serial Is Entered Register Workbook. Open Workbook
Sheets("Data").Visible = True
Sheets("Data").Select
Sheets("Count").Range("B1") = "Registered"
Sheets("Count").Range("A1") = 500
Sheets("Sorry").Visible = xlVeryHidden
Sheets("Count").Visible = xlVeryHidden
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub WrongSerial()
'If Wrong Serial Is Entered Show Only Sheets("Sorry") And Continue To Count Openings.
MsgBox "You have entered wrong serial Number! " & Chr(13) & Chr(13) & _
"This WorkBook will now close!", vbCritical
Sheets("Sorry").Visible = True
Sheets("Sorry").Select
Sheets("Data").Visible = xlVeryHidden
Sheets("Count").Visible = xlVeryHidden
Sheets("Count").Range("A1") = Sheets("Count").Range("A1") + 1
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub
Private Sub LockAndDelete()
Dim sFileName As String, sFilePath As String
'If Not Registerer After Opening 60 Times Delete Sheets("Count") And ("Data")
MsgBox "This Workbook will now close and all data will be lost!", vbCritical
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Sheets("Sorry").Visible = True
Sheets("Sorry").Select
Sheets("Count").Visible = True
Sheets("Data").Visible = True
Sheets("Count").Delete
Sheets("Data").Delete
sFileName = ThisWorkbook.Name
sFilePath = ThisWorkbook.Path
ActiveWorkbook.SaveAs (sFilePath & sFileName), Password:="locked"
Application.Quit
ThisWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Sub ShowMyVeryHiddenSheet()
Sheets("YourSheetName").Visible = True
Sheets("YourSheetName").Select
End Sub
Sub SaveWithoutMacros()
'Purpose : To save a copy of the active workbook without macros
Dim vFilename As Variant
Dim wbActiveBook As Workbook
Dim oVBComp As Object
Dim oVBComps As Object
On Error GoTo CodeError
'Get a filename to save as
vFilename = Application.GetSaveAsFilename(filefilter:="Microsoft Excel Workbooks,*.xls", _
Title:="Save Copy Without Macros")
If vFilename = False Then Exit Sub 'User chose Cancel
ActiveWorkbook.SaveCopyAs vFilename
Set wbActiveBook = Workbooks.Open(vFilename)
'Now strip all VBA, modules, userforms from the copy
Set oVBComps = wbActiveBook.VBProject.VBComponents
For Each oVBComp In oVBComps
Select Case oVBComp.Type
Case 1, 2, 3 'Standard Module, Class Module, Userform
oVBComps.Remove oVBComp
Case Else
With oVBComp.CodeModule 'Worksheet or workbook code module
.DeleteLines 1, .CountOfLines
End With
End Select
Next oVBComp
wbActiveBook.Save
MsgBox "A copy of your workbook has been created with all VBA code removed.", vbInformation, "Success!"
Exit Sub
CodeError:
MsgBox Err.Description, vbExclamation, "An Error Occurred"
End Sub