Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i get a macro excel to execute automatically every 5 seconds 2

Status
Not open for further replies.

RayfromIntech

Electrical
Jun 2, 2003
34
CA
The question pretty much tells it all.
Right now i am using an external program
and doing the sendkeys to ...
It's ok but It would be much better if it was comming from excel.
 
Replies continue below

Recommended for you

There is the Application.OnTime method. It runs your macro on a specified time:
(quote Help file:)
This example runs my_Procedure 15 seconds from now.

Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"

This example runs my_Procedure at 5 P.M.

Application.OnTime TimeValue("17:00:00"), "my_Procedure"

This example cancels the OnTime setting from the previous example.

Application.OnTime EarliestTime:=TimeValue("17:00:00"), _
Procedure:="my_Procedure", Schedule:=False

So you need something like:
Code:
Dim SaveTime as Date    'global variable keeps track of last time run

Sub Macro1()
    SaveTime = Now() + TimeValue("0:00:05")
    Application.OnTime SaveTime, "Macro1", Now() + TimeValue("0:10:00"), True
End Sub
See also Excel VB help.

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top