Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Ontime function

Hi,

I have some code that I want to run every 30 seconds and have the
following:

Application.OnTime Now + TimeValue("00:00:30"), "dowerefresh"

However, what I want is a button to be able to switch it on and off.

I have a public boolean called autorefresh

I was going to do a loop while autorefersh = true, but i'm concerned
that this will just start multiple onTime events?

What is the best way to achieve this?

Thanks for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Ontime function

I would use a checkbox instead of a button. Fill in the checkbox Linked Cell
property to be a cell on the worksheet. Then have your refresh code test the
value of the linked cell.

You will also need a CheckBox1_Click function to start the On time function
the first time

Private Sub CheckBox1_Click()
if Range("A1") = true then

call dowerefresh
End Sub

sub dowerefresh
if Range("A1") = true then
Application.OnTime Now + TimeValue("00:00:30"), "dowerefresh"
end if
end MyOntime

You could also Make the checkbox Linked cell a named range DoRefresh and
then make the test in the above functions

if Range("DoRefresh") = true then

"macroapa" wrote:

Hi,

I have some code that I want to run every 30 seconds and have the
following:

Application.OnTime Now + TimeValue("00:00:30"), "dowerefresh"

However, what I want is a button to be able to switch it on and off.

I have a public boolean called autorefresh

I was going to do a loop while autorefersh = true, but i'm concerned
that this will just start multiple onTime events?

What is the best way to achieve this?

Thanks for any help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Ontime function

If you need to cancel a pending OnTime event, you must provide the
*exact* time that was specified when that event was scheduled. This
means that you should declare a module-scope variable, store the time
in that variable, and use that variable to cancel the OnTime. For
example,

Dim RunWhen As Double

Sub StartTimer()
RunWhen = Now + TimeSerial(0,1,0) ' one minute
Application.OnTime RunWhen,"ProcName",,True
End Sub

Sub StopTimer()
Application.OnTime RunWhen,"ProcName",,False
End Sub

See http://www.cpearson.com/excel/OnTime.aspx for much more
information about working with OnTime and Windows timers.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 22 Oct 2008 03:31:54 -0700 (PDT), macroapa
wrote:

Hi,

I have some code that I want to run every 30 seconds and have the
following:

Application.OnTime Now + TimeValue("00:00:30"), "dowerefresh"

However, what I want is a button to be able to switch it on and off.

I have a public boolean called autorefresh

I was going to do a loop while autorefersh = true, but i'm concerned
that this will just start multiple onTime events?

What is the best way to achieve this?

Thanks for any help.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Ontime function

On 22 Oct, 12:34, Chip Pearson wrote:
If you need to cancel a pending OnTime event, you must provide the
*exact* time that was specified when that event was scheduled. This
means that you should declare a module-scope variable, store the time
in that variable, and use that variable to cancel the OnTime. For
example,

Dim RunWhen As Double

Sub StartTimer()
* * RunWhen = Now + TimeSerial(0,1,0) ' one minute
* * Application.OnTime RunWhen,"ProcName",,True
End Sub

Sub StopTimer()
* * Application.OnTime RunWhen,"ProcName",,False
End Sub

Seehttp://www.cpearson.com/excel/OnTime.aspxfor much more
information about working with OnTime and Windows timers.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
* * Excel Product Group
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)

On Wed, 22 Oct 2008 03:31:54 -0700 (PDT), macroapa



wrote:
Hi,


I have some code that I want to run every 30 seconds and have the
following:


Application.OnTime Now + TimeValue("00:00:30"), "dowerefresh"


However, what I want is a button to be able to switch it on and off.


I have a public boolean called autorefresh


I was going to do a loop while autorefersh = true, but i'm concerned
that this will just start multiple onTime events?


What is the best way to achieve this?


Thanks for any help.- Hide quoted text -


- Show quoted text -


brilliant, thanks guys!
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
Find %ontime & SUMIF ontime ie: find matching sets within Range... Chris T-M Excel Worksheet Functions 3 October 10th 08 08:14 PM
OnTime Function Call Satin Excel Programming 2 May 5th 07 01:50 PM
OnTime bug? Antonio Excel Discussion (Misc queries) 0 June 9th 06 08:24 PM
OnTime function Max Potters Excel Programming 3 September 25th 04 05:59 PM
need a function (not macro with ontime) to record a snapshot of a changing cell Shannon Excel Programming 3 February 2nd 04 06:26 PM


All times are GMT +1. The time now is 11:17 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"