New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Run a Macro Every X Seconds, Minutes, or Hours

Free Excel Macros

Run a Macro Every X Seconds, Minutes, or Hours

Postby Don » Tue Jan 31, 2012 10:30 pm

This Excel macro allows you to run any macro at a set time interval. You can set this to run itself or another macro every so many seconds, minutes, or hours. However, in order for this to work, you will have to run the macro at least once after the workbook in which it is contained is opened. Basically, this macro runs a sort of time loop and, in order to start the loop, you must run the macro at least once.

As it is now, the macro will run itself every interval. So, all you need to do is to put your macro code underneath where it says "Put your code here" and you should be good to go. If you want this to run another macro, just replace "RunMacro" (that comes at the end of the macro) with the name of the macro that you want to run.

By default, this macro runs every 5 minutes. If you want to change that, simply change this part of the code "00:05:00" to whatever you want with hours on the left, minutes in the middle, and seconds on the right.


Where to install the macro: Module


Code: Select all
Sub RunMacro()
   
    'Put your code here
   
    Application.OnTime Now + TimeValue("00:05:00"), "RunMacro"
   
End Sub
Don
Moderator
 
Posts: 733
Joined: Dec 4, 2011
Reputation: 2
Excel Version: 2010

Return to Excel Macros

Who is online

Users browsing this forum: No registered users and 25 guests