Forum Discussion
VBA Timebomb in Excel Spreadsheet
- Aug 30, 2021
Thanks, I think the problem was that the ExpiredDate name refers to the date as a string.
The attached version refers to the date as a date. See if it works for you.
HansVogelaar Thank You very Much Hans for the Reply, I really Appreciate it. Understood on the First Issue, it makes sense else the Date will keep on changing. Please find Attached a Sample Workbook with the Code. Please let me know if you require anything else.
There are two Modules, modTimeBomb with the Code in and unHideDate to show the Hidden Named Range Created.
Regards
Kennedy
Thanks, I think the problem was that the ExpiredDate name refers to the date as a string.
The attached version refers to the date as a date. See if it works for you.
- MCI-ITAug 30, 2021Copper ContributorHans Vogelaar, Absolute Legend!!!!
This Code Seems to Work Better Than My Social Life!
Just a Question or Two:
1. Instead of Showing the Date when I UnHide the Named Range, it shows Numbers, there a Way to Convert that back to Date Show when It will Expire?
2. Instead of Setting it on a Number of Days After First Opening, How can I set a Fixed Date for it to Expire, like 31/12/2021, So it Ignores the 30 Days and Just look for >= 31/12/2021
3. If I protect the VB Project with a Password, will that have any Effect?
Again, Thank You so Much!- HansVogelaarAug 30, 2021MVP
1. Displaying a number is a side effect of using a date instead of a string. It shouldn't really matter.
2. Using a fixed date will greatly simplify the code - no defined name needed:
Sub TimeBombMakeReadOnly() '''''''''''''''''''''''''''''''''''''''''''''''''''''' ' If today is past the expiration date, make the ' workbook read only. '''''''''''''''''''''''''''''''''''''''''''''''''''''' If Date >= DateSerial(2021, 12, 31) Then ThisWorkbook.ChangeFileAccess xlReadOnly ThisWorkbook.Save End If End Sub3. No, that doesn't matter.
- MCI-ITAug 30, 2021Copper ContributorAwesome, Just on Two, Does Formatting have any Influence on the Code, As I understand it, the Code Reads your Short Date Format on your PC, so if it's "31/08/2021" or "08/31/2021" how do you Define that in the Code? Not All Countries or Even PC's in a LAN Might Use the Same Date Format?