Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 11-02-2005, 06:14 AM
davidm davidm is offline
Valued Forum Contributor
 
Join Date: 03 Mar 2005
Posts: 303
davidm is becoming part of the community
How to program a code to die

Please Register to Remove these Ads

There are a few instances when, for good reason, I need to have a code to "expire" after a certain date. I have resorted to a workaround using Worksheet_Open event which immobilizes the code at a set date. But surely, there must be a nifty way of going about it-perhaps using Application.Kill ... but I can't get my head around it. I appreciate any help.
Reply With Quote
  #2  
Old 11-03-2005, 02:22 AM
davidm davidm is offline
Valued Forum Contributor
 
Join Date: 03 Mar 2005
Posts: 303
davidm is becoming part of the community
I am following up on my post which seems to have slipped out of traffic. Thanks in advance of any help.

David
Reply With Quote
  #3  
Old 11-03-2005, 05:45 AM
ste mac
Guest
 
Posts: n/a
Re: How to program a code to die

Hi davidm, this may be something you are looking for..found after a
quick search
of this ng.... Be careful with it... it will delete all the code you
have written.

Option Explicit
Public Sub DeleteAllVBA()
Dim vbComp As Object
For Each vbComp In ActiveWorkbook.VBProject.VBComponents
With vbComp
If .Type = 100 Then
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
Else
ActiveWorkbook.VBProject.VBComponents.Remove vbComp
End If
End With
Next vbComp
End Sub


Public Sub DeleteAllVBA()
For Each book In Workbooks
If book.Name <> ThisWorkbook.Name Then
Dim vbComp As Object
For Each vbComp In ActiveWorkbook.VBProject.VBComponents
With vbComp
If .Type = 100 Then
..CodeModule.DeleteLines 1, .CodeModule.CountOfLines
Else
ActiveWorkbook.VBProject.VBComponents.Remove vbComp
End If
End With
Next vbComp
End If
Next book
End Sub

Here'a another one you may want to play with, as you can pick the
module to delete

Sub deletemodule()

MsgBox "place your code here"

With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With
End Sub

Hope these help

ste



davidm wrote:
> I am following up on my post which seems to have slipped out of traffic.
> Thanks in advance of any help.
>
> David
>
>
> --
> davidm
> ------------------------------------------------------------------------
> davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
> View this thread: http://www.excelforum.com/showthread...hreadid=480988


Reply With Quote
  #4  
Old 11-04-2005, 02:05 AM
davidm davidm is offline
Valued Forum Contributor
 
Join Date: 03 Mar 2005
Posts: 303
davidm is becoming part of the community
Problem solved!

Thanks Mac.

Unfortunately, the idea is not just to delete the code. I need the procedure to self-destruct after a specified date.

I have since my last post been able to come up with the following which serves the purpose. (The message boxes are for debugging only and may not be required in actual application).

Sub CodeToExpireAfterDateA()
Dim x As Date

x = #11/05/2008#
If x > Now() Then
MsgBox "Code is alive" 'optional
Call TimedCode
Else
MsgBox "Code has passed used-by date" 'optional
Exit Sub

End If

End Sub


The routine of course returns "Code is alive" in this instance and calls up "TimedCode". But run after midnight of 11/05/2008, the 2nd message should be returned and the procedure exited.


David


David
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump