Set Wintimer ID

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
I have a wintimer and need help with the following.

I have the timer start if range("A1").value = 1 and end if Range("A1").value = 0

How do I change the ID so that it is directly linked to the cell and I probably wouldn't need the *1000 part as it relies on the cell and not a specific run time.

Code:
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm not sure what you're asking for. The TimerID is just a number which identifies the timer; you can't link it to a cell. Do you mean:
Code:
TimerID = SetTimer(0&, 0&, CLng(Range("A1").Value), AddressOf TimerProc)
where A1 contains the timer interval in milliseconds?
 
Upvote 0
Hi John.

I have trouble sometimes when I run various things it stops the timer working correctly and it runs at double speed and will not stop running unless I actually close the workbook, which is annoying and also it can cause a lot of problems when not running at the correct speed, I have it linked to a cell to start and end but when it goes wrong it doesn't matter what I type in the cell or even call the endtimer statement, it just keeps running.

Someone told me that you need to set the timer ID so that it doesn't lose focus but I didin't know how to do that.
 
Upvote 0
A TimerID is a number allocated by the operating system. You have to declare it as Public at the top of a standard module so that its value is retained whilst the workbook is open, and so that the value can be passed to the KillTimer function to stop the timer. See http://www.cpearson.com/excel/OnTime.aspx.
 
Upvote 0
Thanks John,

I was hoping that there was a solution to make sure that when the endtimer function is called that it makes sure to kill the timer, so that when it loses focus it doesn't keep running or run at double speed etc...

It doesn't haapen all the time, but usually once of twice a day it goes berserk and I have to close my workbook and then reopen it to stop the timer.

Often it happens because I forget to stop the timer when I go in to modify forms or modules in my workbook and that stops it running properly.
 
Upvote 0

Forum statistics

Threads
1,225,218
Messages
6,183,643
Members
453,177
Latest member
GregL65

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