Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Macro to expire after a specified date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dileep Chandran - 17 Sep 2007 07:56 GMT
Hello Masters,

How can I program a macro so that it expires after Jan 01, 2008. Any
help is greatly appreciated.

Thanks
-DC
Mike H - 17 Sep 2007 08:34 GMT
One way

Sub expire()
MyDate = #1/1/2008#
If MyDate < Date Then
   MsgBox "Module expired"
   'exit sub
Else
   MsgBox "Run module"
   'do your stuff
End If
End Sub

Mike

> Hello Masters,
>
[quoted text clipped - 3 lines]
> Thanks
> -DC
I.R;)) - 17 Sep 2007 08:40 GMT
> Hello Masters,
>
[quoted text clipped - 3 lines]
> Thanks
> -DC

if you whant to protect your program? You can do this!

Dim yourdate

Private Sub Workbook_Open()
   yourdate = "Jan 01, 2008"
       If Date > yourdate Then
           Workbooks("name").Close 0
           Application.Quit
        End If
End Sub

P.S You must protect your macro with password!
Dileep Chandran - 17 Sep 2007 11:35 GMT
Thanks a lot Mike and I.R. Both works fine. I appreciate your
immediate assistance.

Regards
-DC
Tom Ogilvy - 17 Sep 2007 11:56 GMT
And it they disable macros (which may be done for them without them even
knowing it), it will have no effect.   Code based workbook protection is
generally a waste of time no matter how elaborate the scheme or how much you
underestimate the intelligence of your users.  

Signature

Regards,
Tom Ogilvy

> Thanks a lot Mike and I.R. Both works fine. I appreciate your
> immediate assistance.
>
> Regards
> -DC
Mike H - 17 Sep 2007 13:06 GMT
Tom,

I agree about code based workbook protection being very flimsy but in this
specific case the OP simply wanted the macro to expire and there was no
mention of 'Users'  to consider the intelligence of, so:-

1. Macros are disabled by whatever method the macro won't run no matter what
the date.
2. Macros are enabled the macro won't after a specific date.

Mike

> And it they disable macros (which may be done for them without them even
> knowing it), it will have no effect.   Code based workbook protection is
[quoted text clipped - 6 lines]
> > Regards
> > -DC
Tom Ogilvy - 17 Sep 2007 15:02 GMT
That is one way to read the question and you are certainly correct on that.

Signature

regards,
Tom Ogilvy

> Tom,
>
[quoted text clipped - 18 lines]
> > > Regards
> > > -DC
Chip Pearson - 17 Sep 2007 14:57 GMT
You could adapt the code on my "Timebombing A Workbook" page at
www.cpearson.com/Excel/WorkbookTimeBomb.aspx . Note that no VBA-based
protection scheme is foolproof. An experienced (and dishonest) user can work
around any protection you provide. However, code such as is on the page
referenced above is "good enough" for the vast majority of users.

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> Hello Masters,
>
[quoted text clipped - 3 lines]
> Thanks
> -DC
pgarcia - 16 Oct 2007 22:13 GMT
Sir,
I want to use your "Time Bomb" VB code, but I have question on the "Defined
Name". What name is it that we are to remove from the VB code?
Thanks

> You could adapt the code on my "Timebombing A Workbook" page at
> www.cpearson.com/Excel/WorkbookTimeBomb.aspx . Note that no VBA-based
[quoted text clipped - 9 lines]
> > Thanks
> > -DC
Chip Pearson - 20 Oct 2007 20:28 GMT
Specifically what piece of code are you referring to? The web page provides
several different methods of time bombing a workbook. The first one
described on the page uses a defined name called "ExpirationDate" that
contains the data after which the workbook is unusable.  If you want to
remove the time bombing, you should delete that name. Of course, then next
time you open the workbook the name will be recreated. To permanently remove
the time bomb, you need to delete the VBA code.

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> Sir,
> I want to use your "Time Bomb" VB code, but I have question on the
[quoted text clipped - 16 lines]
>> > Thanks
>> > -DC
pgarcia - 22 Oct 2007 17:28 GMT
Thanks, also, do you put this in the "This Workbook" or it's module?

Option Explicit

Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90

Sub TimeBombWithDefinedName()
Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number <> 0 Then
   NameExists = False
   ExpirationDate = CStr(DateSerial(Year(Now), _
       Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
   ThisWorkbook.Names.Add Name:="ExpirationDate", _
       RefersTo:=Format(ExpirationDate, "short date"), _
       Visible:=False
Else
   NameExists = True
End If

If CDate(Now) > CDate(ExpirationDate) Then
   MsgBox "This workbook trial period has expired.", vbOKOnly
   ThisWorkbook.Close savechanges:=False
End If

End Sub

> Specifically what piece of code are you referring to? The web page provides
> several different methods of time bombing a workbook. The first one
[quoted text clipped - 24 lines]
> >> > Thanks
> >> > -DC
pgarcia - 30 Oct 2007 17:03 GMT
Sorry to bother you, but did you reply to my last post?

> Specifically what piece of code are you referring to? The web page provides
> several different methods of time bombing a workbook. The first one
[quoted text clipped - 24 lines]
> >> > Thanks
> >> > -DC
Chip Pearson - 03 Nov 2007 17:37 GMT
I don't recall if I read it or not.

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> Sorry to bother you, but did you reply to my last post?
>
[quoted text clipped - 31 lines]
>> >> > Thanks
>> >> > -DC
LuisE - 26 Dec 2007 19:42 GMT
Chip,

Is the same approach used when a "commercial" add-in requieres registration
after a trial period, do you know how it would work?

Do you have any literature on it?

Thanks

> I don't recall if I read it or not.
>
[quoted text clipped - 33 lines]
> >> >> > Thanks
> >> >> > -DC
swiftcode - 18 Mar 2008 08:33 GMT
Hi Chip,

Your code is great, but I seem to have encountered a problem. The code
creates the "ExpirationDate" fine on one machines with the value being the
date e.g. 39555, whilst on a different machine it is being captured as a text
e.g. "18-03-08".

I have changed the the visibility to true so that i could see the value.

ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=True

I have checked all the settings in excel but could find no differences on
either machines.

Do you have any idea?

Thanks

> I don't recall if I read it or not.
>
[quoted text clipped - 33 lines]
> >> >> > Thanks
> >> >> > -DC
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.