Help to set expired day to open excel file

nhnn1986

Board Regular
Joined
Oct 12, 2017
Messages
92
Hi all

I have workbook shared to someone, but I want this excel file can open if the day before 31/12/2019. If file open on day after 31/12/2019 will have pop up messegbox "File was experidated" then delete this file when user click "OK" button in Pop up.

Please help me to do that, thanks./.
 
@nhnn1986

Here's what I did in one of my workbooks-

Code:
Private Sub Workbook_Open()

'Copy and paste this into the Microsoft Excel Objects-> "ThisWorkbook" tab


'You need to remove the apostrophe in the below comment before using if desired- it will hide excel when the code first runs
'and if the code runs correctly, will show excel. If you happen to have an issue (say expired workbook) while this is running,
'you can double click the workbook again and it will force it to show


'Hides application
'Application.Visible = False


'defines code strings
Dim edate As String
Dim d As String
Dim ExpirationDate As String


'sets the variables
'so in this code I used a hidden sheet called "Developer" to house the date of expiration for me, you will need to set
'"developer" to the name of your sheet


ExpirationDate = edate
d = Sheets("Developer").Range("B39")          'registration key - a "password" that I had in a cell - if the user input this password it would reset the expiration date
edate = Sheets("Developer").Range("E37")      'expiration date - a date in a cell for expiration




'code checks to see if today's date is valid compared to your pre-defined expiration, if yes, shows excel and selects sheet
'"xxx". Make sure to change the name of xxx to your desired sheet.
If ExpirationDate < Date Then
     Application.Visible = True
     Sheets("xxx").Select
     End If
     
'this is where things are fun- I used "Developer" again as my sheet- so in "Developer", Cell C36 had a date. Cell D36 (not mentioned/needed here)
'had a number- this was the number of days after C36, for which the workbook was good, and then C36+D36=E37. E37 was the "expiration" of the workbook
'C36 was reset to today's date if the program was expired AND the user input the password you had typed in "B39"
Else: d = Application.InputBox("Your workbook date has expired. Please enter the registration key to renew your license.")
     If d = CStr(Worksheets("Developer").Range("B39").Value) Then
           Sheets("Developer").Range("C36") = Date
           MsgBox "Welcome Back " & s, vbOKOnly, namer
           End If
     End If
    
        
        
End If
Application.Visible = True   'inserted just to check workbook
'Protects/Hides sheets on startup


    
End Sub
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
No problem! Let me know how it goes! Just open vba editor and paste! Oh, and don't forget to either make an excel sheet named "Developer" or change the name of "Developer" to a sheet you currently have. I'm online for another hour and a half if you need help tonight!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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