Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    detect running Application.OnTime (Word 2000)

    A cursory Google Search and search of Google groups turns up no answers, so this is a long shot, but .....

    I make use of "Application.OnTime" in Microsoft Word 2000.
    It works fine in my little appliaction.
    I wonder what happens if, say, a load a second copy of my application - perhaps the first is stalled on a Breakpoint and I load a second copy.
    The AutoExec fires up and issues a second Application.OnTime which I presume is now running in parallel with the first.
    I clear the breakpoint, and the first Application.OnTime sees its chance, runs, and re-institutes itself for 5 minutes down the road.
    A minute later, the second Application.OnTime sees its chance, runs, and re-institutes itself for 5 minutes down the road.

    Do these two macros-in-waiting play leap-frog down the long avenue of confusion?

    Is there a way to detect such a Word macro which is waiting in the wings?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: detect running Application.OnTime (Word 2000)

    If you open a shortcut to Word while Word is running, it doesn't start a new instance of Word but opens a blank new document in the running instance, so your AutoExec macro isn't run.

    In normal circumstances, the only way to start a new instance of Word is by using CreateObject in VBA.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    >the only way to start a new instance of Word is by using CreateObject in VBA
    You know how I hate to disagree with you, Hans, but ..... <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    I often (once a day?) end up with two copies of Word running, as a sort-of end user, in the situation I've described.
    Perhaps I have a dialog box open in my only running copy of Word, and double-click a *.doc in Explorer. I'll note it next time it happens.
    I know it happens because in the second copy of Word, I close the one or two files and am left with a document-empty copy of Word.
    I close that, and find (Alt-Tab) myself back in the original copy with the dialog/breakpoint/whatever open, hanging there. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: detect running Application.OnTime (Word 2000)

    I'm using Word 2002 (in Office XP) and even if a dialog box is open or code is being paused, double-clicking a document in Windows Explorer won't start a second instance of Word, it'll wait until the dialog has been closed or the code finished or ended. The same holds for Word 2003.
    Perhaps it was different in Word 2000.

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: detect running Application.OnTime (Word 2000)

    <P ID="edit" class=small>(Edited by wdwells on 15-Nov-08 16:00. "Using Word 2003" added)</P>Hi Chris
    Using Word 2003
    I had a terrible time breaking my users from the habit of exiting from word then double clicking a document icon when they wanted to switch documents. I have an AutoExit procedure in one of the add-ins, and if they attempted to launch Word in this manner while it was still in the process of exiting -- as a consequence the AutoExit procedure running -- a second instance of Word was launched. This resulted in a warning that the Normal template was in use. It also resulted in an inordinate number of Word crashes.
    Regards
    Don

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: detect running Application.OnTime (Word 2000)

    Further to my last post. On launching, one of the add-ins (A), has the ability to replace the add-in (, containing the AutoExit procedure. And! wouldn't you know it; add-in B has the ability to replace A.

    Wouldn't that produce a wonderful Alphonse and Gaston rouitine?
    Regards
    Don

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    >Perhaps it was different in Word 2000.
    I'm using 2000.
    I'll keep an eye open and post here next time I catch it. I know it happens. It happened yesterday.
    Attached Images Attached Images
    • File Type: jpg 1.JPG (4.9 KB, 1 views)

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    >a second instance of Word was launched.
    I see your Word 2003. I have a copy here but rarely use it.

    Are you saying that you/your users are able to launch a second copy of Word2003?

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    >Is there a way to detect such a Word macro which is waiting in the wings?

    To date noone seems to have addressed my concern, so I repeat it here.
    It's an Application.OnTime issue, and the possibility, no matter how it arises, of having multiple instances of a macro waiting in the wings.
    Specifically, has anyone heard of way to detect such a scheduled task?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: detect running Application.OnTime (Word 2000)

    You could set a global variable at the same time you call Application.OnTime, and check for the value of this variable:

    Public blnStarted As Boolean

    Sub Test()
    If blnStarted Then Exit
    blnStarted = True
    Application.OnTime Now + TimeValue(0, 5, 0), "SomeOtherMacro"
    End Sub

    But this will only work within the same instance of Word. I don't know of any way one instance of Word could check whether OnTime has been activated in another instance.

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    >I don't know of any way one instance of Word could check whether OnTime has been activated in another instance.

    Thanks, Hans.
    I suspect it would involve serious digging using Windows DLL's to locate a list of outstanding tasks.
    My guess too is that such a macro might not be seen as an outstanding Windows task, but would remain in the bailiwick of Word itself. I can't see Windows caring about running a Word macro at 11:00 a.m. when Word is no longer around.

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: detect running Application.OnTime (Word 2000)

    Hi Chris

    >>Are you saying that you/your users are able to launch a second copy of Word2003?

    YES!

    Try the following test with the two attached files. This is how it acted on my installation of 2003 running on XP.
    1. <LI>Save the two attached files to an open empty folder ( New Folder ).
      <LI>Close all open documents in Word
      <LI>Open OnTime 2.doc
      <LI>Enable the macros when asked.
      <LI>Key in Alt + F8
      <LI>Select OnTime 2.doc from the "Macros in" drop down list
      <LI>Run the delay macro
      <LI>Activate New Folder
      <LI>Double click OnTime 1.doc
      <LI>Wait; about one minute after running the delay macro. the second instance of Word will launch
      <LI>Enable the macros when asked
      <LI>Normalize both Word windows and arrange them such that they do not obscure the center of the desktop.
      <LI>Activate OnTime 1.doc
      <LI>Key in Alt + F8
      <LI>Select OnTime 1.doc from the "Macros in" drop down list
      <LI>Run the caller macro
      <LI>Activate OnTime 2.doc
      <LI>Key in Alt + F8
      <LI>Run the caller macro
    Both of the macros should run, presenting messages that they were called from OnTime 1 or 2. They will not run in any particular order. I suspect that one is always running in the background until it is able to display the message box, then the other is running in the background. Each macro will present the message box ten times.

    You should note that each document will present its own instance of VBE.
    Attached Files Attached Files
    Regards
    Don

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: detect running Application.OnTime (Word 2000)

    Yes, in this situation two instances of Word will run.
    Using a loop that consumes 100% of processor capacity is *VERY* bad programming of course.

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    As far as I know, Word only remembers the last OnTime that has been set, discarding all others. So only the last Ontime that has been scheduled will run anyway.

    If the project is yours, you could set something in the registry when doing the schedule and check against that registry entry to see if another ontime had been scheduled already
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  15. #15
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect running Application.OnTime (Word 2000)

    > You should note that each document will present its own instance of VBE.
    Thanks Don, I saw only the Ontime1 MsgBox pop up, but the presence of two VBEs confirms my suspicions of two instances of Word 2000 running.
    I note Hans's and Jan Karel's comments.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •