Time Lapsed code to delete code !

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
433
Hi All

What sort of code would I need to write which could be triggered by a date and effectively delete VBA Code?

I have something that needs to run till a said time and then be deleted as it could interfere with other codes running after this time.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Thanks for this its really helpful.

Just one area I'm having toruble with is getting it to run only on a set date.

My initial thought was to ahve the function Now() embedded into a worksheet and then name this cell DAY - then use this as a variable in the project coding Dim DAY but I';m struggling to get the VBE code to understand that If DAY = 19/05/2011 (don't care the format) then execute code - if it does not state this date exit the code without running.

Any ideas?
 
Upvote 0
Try using TODAY() instead of NOW()

or maybe just

Code:
If Date = DateValue("19/05/2011") Then
 
Upvote 0
.. Just one thing more.

Will this code automatically execute or will I need to set an event procedure?

HTML:
Sub DeleteAllVBACode()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Dim CodeMod As VBIDE.CodeModule
        
        Set VBProj = ActiveWorkbook.VBProject
        
        If Date = DateValue("20/05/2011") Then
        
        For Each VBComp In VBProj.VBComponents
            If VBComp.Type = vbext_ct_Document Then
                Set CodeMod = VBComp.CodeModule
                With CodeMod
                    .DeleteLines 1, .CountOfLines
                End With
            Else
                VBProj.VBComponents.Remove VBComp
            End If
        Next VBComp
        Else: Exit Sub
        End If
    End Sub
 
Upvote 0
It won't run by itself. You could place a call to it in the Workbook_Open event in ThisWorkbook.
 
Upvote 0
Ok I'm having a bad moment here, why cannot I not get a call procedure to work?

I was putting in the This workbook area

Sub Workbook_Open()
GoTo (then the Sub name)
End Sub

Should I use something other than GoTo?
 
Upvote 0
I ahve not used a Call code before can anyone give me the guidance in what i should be using?

This is upon a Sub Workbook_Open()

to Call a piece of code called TimePlease which is a Sub not private sub
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top