PDA

View Full Version : Solved: Run macro only once within 20 hours



jazznaura
11-28-2007, 10:18 AM
Hi all,
Just a quick question.
Is it possible to stop a macro from being ran more than once in any 20-24 hour period ?
thanks
Jazz Naura

Bob Phillips
11-28-2007, 10:27 AM
Dim runDate As Date

runDate = Date - 1
On Error Resume Next
runDate = Evaluate(ThisWorkbook.Names("_RunDate").RefersTo)
On Error GoTo 0
If runDate < Date Then
Call myMacro
ThisWorkbook.Names.Add Name:="_RunDate", RefersTo:=Date
End If

jazznaura
11-28-2007, 10:34 AM
thanks for the reply.

will i need to update the date everyday ?

jazznaura
11-28-2007, 10:39 AM
i was thinking limit someone from running a macro more than once in any 24 hr period.

some code you can put in once and leave.

Possible ?

unmarkedhelicopter
11-28-2007, 10:44 AM
That's what the code does ...
Well ... nearly ... if the code was run today, it won't let you run it again, but if it was run at 23:59 you could run it 2 minutes later.
"myMacro" is the code we are talking about only running once per day.
Of corse if the name is public then this will not prevent them from seeing it and running it anyway.

jazznaura
11-28-2007, 10:57 AM
oh right sorry misunderstood the code, i'm still learning. will try it out.

thanks to all for the quick response.