![]() |
#1
|
|||
|
|||
![]()
What is the best way to make a macro time out?
I have a macro that will be used globally but don't want them to be able to use it forever. I wrote in some code that times out the macro based on the system date. Unfortunately, in other countries they set their system clock formats differently so my code doesn't work on their pc's. What's a good way to do this? |
#3
|
|||
|
|||
![]()
Alex can never be stumped
![]() |
#4
|
||||
|
||||
![]()
Well, here is a small piece of code which will not work after, say, Jan 1, 2006:
Code:
Sub MyMacro() If Date > DateSerial(2006, 1, 1) Then MsgBox "Sorry, this function expired", vbCritical Exit Sub End If ' Do something End Sub You can do a lot of interesting things with dates. For example, you can subtract two dates to determine the difference in days between them. You can use this in your macro too: Code:
Sub MyMacro2() Dim Expiry As Date Expiry = DateSerial(2005, 1, 1) If Date > Expiry Then MsgBox "Sorry, this function expired " & (Date - Expiry) & " days ago", vbCritical Exit Sub End If ' Do something End Sub |
#5
|
|||
|
|||
![]()
will this code work if they have european time? example: 2005/02/07
i would like for this to work globally. |
#6
|
||||
|
||||
![]()
Yes, the "Date" data type is locale invariant. However when you print the date, it will appear differently on different locales. Or if you use the "#" notation to represent a date, such as in:
Code:
Sub DateExample() Dim d As Date d = #2/7/2005# MsgBox Format$(d, "mmmm d, yyyy") End Sub |
#7
|
||||
|
||||
![]()
My concern was if the user changes there system date back a few days they could easily fool the expire date. So here is what I come up with:
Code:
If IsNull(ActiveDocument.Properties("GraniteFills", 1)) = True Then ActiveDocument.Properties("GraniteFills", 1) = Date ElseIf ActiveDocument.Properties("GraniteFills", 1) < Date Then ActiveDocument.Properties("GraniteFills", 1) = Date End If Dim Expiry As Date Expiry = DateSerial(2005, 2, 9) If ActiveDocument.Properties("GraniteFills", 1) > Expiry Then MsgBox "Your copy of the Granite Fills program expired " & (ActiveDocument.Properties("GraniteFills", 1) - Expiry) & " days ago.", vbCritical, "Granite Fills" Exit Sub End If Thanks, Shelby |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Someone make an Active List Font macro | dungbtl | CorelDRAW/Corel DESIGNER VBA | 8 | 28-10-2019 09:53 |
Trying to get my Time Recording script running... | johndankey | CorelDRAW/Corel DESIGNER VBA | 12 | 26-04-2004 22:48 |
An Idea for a handy and easy to make macro | vallentin | Macros/Add-ons | 2 | 16-03-2004 11:35 |
New macro to clip curves w.r.t. a border | Gerard Hermans | Macros/Add-ons | 0 | 09-06-2003 07:50 |
Speeding up a macro | Rick Randall | CorelDRAW/Corel DESIGNER VBA | 2 | 12-12-2002 10:51 |