LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default cant stop OnTime initiated macro, etc

Nathan,

Is your workbook_open event code in ThisWorkbook code module. It needs to be
there not in a standard code module.

It won't stop, as OnTime is part of the Application object, so continues
when the workbook closes, and will continue so until Excel ends or it is
stopped. To stop it, you need to save the details when you start it, and
re-issue exactly the same command with Schedule = False.

Chip Pearson has a good explanation at
http://www.cpearson.com/excel/ontime.htm

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"nathan" wrote in message
...
I am having two problems with a macro that i want to run continuously when

the workbook it resides in is opened:

1) it will not run automatically when the workbook is opened as I want it

to. i have to start it manually.
2) it will not stop when the workbook is closed. it keeps running as long

as excel is open and relaunches the workbook on the stated schedule. I
don't want it to run when the workbook is closed.

Below is the macro, thank you!:

Private Sub workbook_open()
'starts when the workbook is opened and schedules the leverage macro

procedure to run every minute
Application.OnTime Now() + TimeValue("00:01:00"), "leverage"

End Sub

Sub leverage()
a = ThisWorkbook.Name
If Workbooks(a).Worksheets("a.book").Range("a7").Valu e < 10 Then
workbook_open
Else: Dim msg, style, title, response
msg = "Leverage is 10 or greater!!"
style = vbOKOnly + vbExclamation + vbCritical +

vbDefaultButton1 + vbApplicationModal + vbMsgBoxSetForeground
title = "WARNING!!"
response = MsgBox(msg, style, title)
workbook_open
End If
End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find %ontime & SUMIF ontime ie: find matching sets within Range... Chris T-M Excel Worksheet Functions 3 October 10th 08 08:14 PM
links initiated by cell data JB Excel Discussion (Misc queries) 10 June 14th 08 01:26 PM
How does msgbox stop the OnTime event? Emile van Mierlo Excel Programming 12 May 4th 04 01:10 PM
need a function (not macro with ontime) to record a snapshot of a changing cell Shannon Excel Programming 3 February 2nd 04 06:26 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 11:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"