Stop code running

K

kevin carter

Hi,
i have this code running in a workbook, te code calls a macro that
updates all the links in the workbook

Sub auto_open()

ThisWorkbook.Application.OnTime TimeValue("06:05:00"), "update"
ThisWorkbook.Application.OnTime TimeValue("07:05:00"), "update"
ThisWorkbook.Application.OnTime TimeValue("08:05:00"), "update"
ThisWorkbook.Application.OnTime TimeValue("09:05:00"), "update"
end sub

this works fine
however i am fnding that when i close this workbook and have another
workbook open at the te macros is due to run this workbook opens

How can i stop the code running when i close this workbook

thanks

kevin
 
D

Dave Peterson

Take a look at Chip Pearson's notes:
http://www.cpearson.com/excel/OnTime.aspx

But you may want to try:

Sub Auto_Close()
On Error Resume Next

Application.OnTime EarliestTime:=TimeValue("06:05:00"), _
Procedure:="update", Schedule:=false

Application.OnTime EarliestTime:=TimeValue("07:05:00"), _
Procedure:="update", Schedule:=false

Application.OnTime EarliestTime:=TimeValue("08:05:00"), _
Procedure:="update", Schedule:=false

Application.OnTime EarliestTime:=TimeValue("09:05:00"), _
Procedure:="update", Schedule:=false
 
K

kevcar40

Take a look at Chip Pearson's notes:http://www.cpearson.com/excel/OnTime.aspx

But you may want to try:

Sub Auto_Close()
    On Error Resume Next

    Application.OnTime EarliestTime:=TimeValue("06:05:00"), _
         Procedure:="update", Schedule:=false

    Application.OnTime EarliestTime:=TimeValue("07:05:00"), _
         Procedure:="update", Schedule:=false

    Application.OnTime EarliestTime:=TimeValue("08:05:00"), _
         Procedure:="update", Schedule:=false

    Application.OnTime EarliestTime:=TimeValue("09:05:00"), _
         Procedure:="update", Schedule:=false

    On error goto 0
End Sub











--

Dave Peterson- Hide quoted text -

- Show quoted text -

thank you dave i will try it now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top