ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run a Macro at a certain time (https://www.excelbanter.com/excel-discussion-misc-queries/256937-run-macro-certain-time.html)

jswalsh33

Run a Macro at a certain time
 
I have tried to use Mike H's answer to Running Excel macro as a service
dated 9/30/2008.

I have us the task Scheduler to open the Excel Workbook containing the macro
I want to run with a time of 2:00 AM.

When I put the code Application.OnTime TimeValue("02:01:00"), "Merge" as the
first line of the Macro Merge, nothing happens when 02:01:00 comes.

What am I doing wrong?

Jim Walsh

Mike H

Run a Macro at a certain time
 
Hi,

To get the macro to run using ontime you have to start things off like this

Private Sub Workbook_Open()
Application.OnTime TimeValue("02:00:00"), "Merge"
End Sub

or you can put it in another sub and run that and at the alloted time your
macro will run

Sub Get_Things_Going()
Application.OnTime TimeValue("02:00:00"), "Merge"
End sub


Sub Merge()
'Your code
End Sub




--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"jswalsh33" wrote:

I have tried to use Mike H's answer to Running Excel macro as a service
dated 9/30/2008.

I have us the task Scheduler to open the Excel Workbook containing the macro
I want to run with a time of 2:00 AM.

When I put the code Application.OnTime TimeValue("02:01:00"), "Merge" as the
first line of the Macro Merge, nothing happens when 02:01:00 comes.

What am I doing wrong?

Jim Walsh


jswalsh33

Run a Macro at a certain time
 
Thanks Mike, That worked fine.

Jim Walsh

"Mike H" wrote:

Hi,

To get the macro to run using ontime you have to start things off like this

Private Sub Workbook_Open()
Application.OnTime TimeValue("02:00:00"), "Merge"
End Sub

or you can put it in another sub and run that and at the alloted time your
macro will run

Sub Get_Things_Going()
Application.OnTime TimeValue("02:00:00"), "Merge"
End sub


Sub Merge()
'Your code
End Sub




--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"jswalsh33" wrote:

I have tried to use Mike H's answer to Running Excel macro as a service
dated 9/30/2008.

I have us the task Scheduler to open the Excel Workbook containing the macro
I want to run with a time of 2:00 AM.

When I put the code Application.OnTime TimeValue("02:01:00"), "Merge" as the
first line of the Macro Merge, nothing happens when 02:01:00 comes.

What am I doing wrong?

Jim Walsh



All times are GMT +1. The time now is 03:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com