![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: San Antonio, TX
Posts: 186
|
I know I saw it here someplace prior, but can't find it now.......
I have a macro that I want to run every 6 hours, as long as the workbook is open, but I do not know how to code that, can anyone help me?? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi ermccarthy,
Just put this line of code inside your macro (say its name is "MyMacro"): Application.OnTime Now() + 6/24, "MyMacro" Now all you need to do is run MyMacro, and it will reschedule itself for 6 hours in the future, and will continue to do so each time it runs. You can either run it manually when you first open the workbook, or call MyMacro from the workbook's Open event so that it will automatically run when the workbook opens. To do this, just insert the code Private Sub Workbook_Open() MyMacro End Sub into the ThisWorkbook code pane (right-click on the Excel icon on the Excel menu toolbar, select View Code, and paste it into the code pane.
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|