Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Can a macro read the call stack? (Word 2000)

    My application calls a macro from the WindowActivate event. There are two contexts in which this can happen: when the user activates a window, and when a macro executes the Activate method on a document object.

    In the former case it's essential that my event handling code be executed. In the latter case is unnecessary; it should also be harmless, but it's not. All sorts of weird things happen, resulting in program malfunctions and often crashing Word.

    I would like to make WindowActivate determine what activated a window and proceed normally if the user did it, but do nothing if a macro did it. Is there any reliable way to do that? It should be easy if I can read the call stack, but I can't find a way to get at it.

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a macro read the call stack? (Word 2000)

    The only way I know of doing this would be to write code in a language like C that you would call from VBA.
    Legare Coleman

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Can a macro read the call stack? (Word 2000)

    Try setting a global variable: Dim blnMacroIsRunning As Boolean, turn it on when you start your code and off when you stop, and check the value inside your event handler to avoid the problem. It's not the prettiest programming, but then, there are only 24 hours in the day.

  4. #4
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Can a macro read the call stack? (Word 2000)

    Yes, that's what I did when it appeared I would not find a better solution. I agree with your assessment: ugly, but it works.

Posting Permissions

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