Excel

Create a timer to run a macro

Ease of Use

Intermediate

Version tested with

2010 

Submitted by:

Paleo

Description:

A macro will be run after a certain time 

Discussion:

Sometimes you create a macro you want to run several times, after a specified time interval. When you run "minhaMacro" bellow you will make it run after each 15 minutes, and if you ever need it to stop, simply run "paraTimer". 

Code:

instructions for use

			

Public Sub minhaMacro() On Error Resume Next MsgBox ("Time elapsed!") ' Here you would insert your real code Application.OnTime EarliestTime:=Now + TimeValue("00:15:00"), Procedure:="minhaMacro" ' set to 15 minutes End Sub

How to use:

  1. Create a command button (cmdStart) for starting the counter, in the Main sheet
  2. Goto Excel --> Tools --> Macro --> Visual Basic Editor (Or Press Alt + F11)
  3. In VBE window, goto Insert --> Module
  4. Double Click the Module1 and paste the code shown above.
 

Test the code:

  1. Click the Start button.
 

Sample File:

timer.zip 15.5KB 

Approved by Jacob Hilderbrand


This entry has been viewed 448 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express