Forum Discussion
MCI-IT
Aug 30, 2021Copper Contributor
VBA Timebomb in Excel Spreadsheet
MS Excel 365 MSO (16.0.14326.20164) 64-bit Good Day, I do hope I'm in the Right Forum, if not My Apologies, and can I get directed to the Correct One? My Apologies if what I am saying or as...
- 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.
MCI-IT
Aug 30, 2021Copper Contributor
Hans 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!
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!
HansVogelaar
Aug 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 Sub
3. 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?
- HansVogelaarAug 30, 2021MVP
Both versions of the code that I posted are independent of the system date format of the user.
Your original version used the user's short date format, which might be different from that of another user - I think that caused the code to fail to work correctly.
- MCI-ITAug 30, 2021Copper ContributorThank You! I am going to go Play with the Code and see Where I fall Short...
I really Appreciate All the Help!
Just a Question, If You Had to Do it, How Would You Doing and Code IT?