Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Run Sub automatically on periodic basis

Hi,

I am using Excel 2007. I have written a Subroutine that I want to run
automatically once every thirty seconds without any user interaction. Can
anyone tell me how I can set this up?

Thanks in advance,
Paul

--
Paul Kraemer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Run Sub automatically on periodic basis

This code will run your procedure when the workbook has been opened. At the
end of your code the OnTime event will schedule another run of your code 30
seconds later. Thus, it will continue to loop until you close the workbook.
Hope this helps! If so, let me know, click "YES" below.

Private Sub Workbook_Open()
Call my_Procedure
End Sub

Sub my_Procedure()

' your code here

Application.OnTime EarliestTime:=Now + TimeValue("00:00:30"),
Procedu="my_Procedure"

End Sub
--
Cheers,
Ryan


"Paul Kraemer" wrote:

Hi,

I am using Excel 2007. I have written a Subroutine that I want to run
automatically once every thirty seconds without any user interaction. Can
anyone tell me how I can set this up?

Thanks in advance,
Paul

--
Paul Kraemer

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run Sub automatically on periodic basis

You provided no code for stopping the proc from rescheduling itself.
To end an OnTime event, you must provide it the EXACT time that it is
scheduled to run. Since you use Now+TimeValue(), you have no way of
getting the scheduled run time. Instead, you should save the time
value in a module-scoped variable and pass the value of that variable
to OnTime. E.g.

Dim RunWhen As Double
Sub my_Procedure()
' your code here
RunWhen = Now + TimeSerial(0,0,30)
application.ontime EarliestTime:=RunWhen, _
Procedu="my_Procedure"
End Sub

Sub StopOnTime
Application.OnTime earliesttime:=RunWhen, _
procedu="my_Procedure", schedule:=False
End Sub

See www.cpearson.com/Excel/OnTime.aspx for more detail about working
with OnTime and Windows timers.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Mon, 1 Feb 2010 12:03:01 -0800, Ryan H
wrote:

This code will run your procedure when the workbook has been opened. At the
end of your code the OnTime event will schedule another run of your code 30
seconds later. Thus, it will continue to loop until you close the workbook.
Hope this helps! If so, let me know, click "YES" below.

Private Sub Workbook_Open()
Call my_Procedure
End Sub

Sub my_Procedure()

' your code here

Application.OnTime EarliestTime:=Now + TimeValue("00:00:30"),
Procedu="my_Procedure"

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I automatically reset numbers to 0 on a daily basis? [email protected].(donotspam) Excel Discussion (Misc queries) 3 December 10th 08 05:17 PM
Automatically create list in different sheet on basis of other lis Pair_of_Scissors[_2_] Excel Worksheet Functions 1 June 12th 08 05:59 PM
How do I update graphs automatically with periodic data updates Infinitejest Charts and Charting in Excel 2 October 28th 06 09:02 PM
Summing periodic sales on a rolling basis JohnnStar Excel Worksheet Functions 2 July 21st 06 01:17 PM
Periodic Calculating Peter B Excel Worksheet Functions 1 December 8th 04 09:31 AM


All times are GMT +1. The time now is 03:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"