Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng 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
Joined
Jun 2, 2003
Messages
34
Location
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.
 
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

Back
Top