![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
I need to run it every 90 mins. Thanks
|
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Hi
Try Sub StartOff() Application.OnTime Now + TimeValue("00:90:00"), "DoIt" End Sub Sub DoIt() Run "StartOff" 'Your Code End Sub |
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
I get an error on sub startoff
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
|
Make a small change as follows:
Public ThisTime As Double Sub StartOff() ThisTime = Now + TimeValue("00:90:00") Application.OnTime earliesttime:=ThisTime, procedure:="DoIt" Sub DoIt() Run "StartOff" 'Your Code End Sub |
|
|
|
|
|
#5 |
|
Guest
Posts: n/a
|
I am still getting an error BTW I am using Excel 97 if that matters
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Sub DoIt() 'Your Code Run "StartOff" End Sub Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
|
silly me - you need to change
ThisTime = Now + TimeValue("00:90:00") to ThisTime = Now + TimeValue("01:30:00") as you as time is in hh:mm:ss or you will get adata type mismatch (also forgot the end sub before sub DoIt()) |
|
|
|
|
|
#8 |
|
Guest
Posts: n/a
|
Sam S that works! thanks
|
|
|
|
#9 |
|
Guest
Posts: n/a
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
I had this similar problem. I have some code that someone on this board helped me with (I'm sorry, i dont remember who
The problem youre having is that the code is still being run eventhough the file is closed. To stop this, you need to disable the counter. Im not the best person to tell you exactly how to do that but, heres the code I use: In "ThisWorkbook" I have this code: 'This disables the time coutner and resets it when a caculation is made Private Sub Workbook_SheetCalculate(ByVal Sh As Object) Call Disable Call SetTime End Sub 'This disables the time counter and resets it when a sheet is changed Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range) Call Disable Call SetTime End Sub and in a module, i have this code: Dim DownTime As Date 'This is the code that the macros in ThisWorkbook calls to set the timer Sub SetTime() DownTime = Now + TimeValue("00:15:00") Application.OnTime DownTime, "ShutDown" End Sub 'This is the code that the macros in ThisWorkbook calls to close the file Sub ShutDown() ActiveWorkbook.Save ActiveWorkbook.Close End Sub 'This is the code that the macros in ThisWorkbook calls to disable the timer Sub Disable() On Error Resume Next Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", Schedule:=False End Sub Im assuming youll need something similar to the Disable code. Hope this helps some |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|