Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trapping what triggered AutoOpen (Word97/NT)

    Hi

    I run a macro in a project containing many subs and functions, including an AutoOpen. The AutoOpen triggers unexpectedly. I try to track down the line of code that caused it to trigger:<UL><LI>I look in the stack, but it only goes back to AutoOpen.
    <LI>I try disabling auto macros by putting "Wordbasic.DisableAutoMacros 1/0" at the beginning and end of the subroutine containing the MsgBox. No joy.
    <LI>I progressively move a Stop statement around until I find the apparent trigger. It's a simple MsgBox statement.
    <LI>If I put the Stop statement one line before the MsgBox, the macros stop at that point, as expected. If I put it one line after, I get "cannot execute in break mode" (presumably because the AutoOpen tried to execute).[/list]Any ideas?
    Dale

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Not without seeing the document or template.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    autoopen will run only when a doc is opened or if it is explicitly called.

    try putting a STOP statement in AutoOpen itself, thn step thru the code to find the point AFTER which the AutoOPen was called.
    Should be some statement that opens a doc or explicitly calls autoopen.

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Howard
    That's why I'm confused. AutoOpen appears to be being triggered by a MsgBox statement.<UL><LI>If I put Stop before the MsgBox, it stops gracefully.
    <LI>If it goes after the MsgBox, I get "cannot execute in break mode".
    <LI>If I don't have any Stop statement in that macro, the AutoOpen gets executed.
    <LI>If I comment out the MsgBox statement, the AutoOpen gets executed.[/list]Maybe I need to "clean" the project.

    Hans
    It's a bit of a brute, but here are the two key macros.

    Yours in bewilderment
    Dale

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Dale, are you sure the MsgBox is causing the AutoOpen when you state "If I comment out the MsgBox statement, the AutoOpen gets executed"

    Why have you disabled the DisableAutoMacro lines in the code you are using? Did that not work?

    Looking at the code it appears there is a bit of opening and closing of files going on - Documents.Add for instance and the user is prompted to potentially perform another in the View HTML message box. Any file opening is potentially going to kick off the autoopen macro.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hi Andrew

    I tried disabling auto macros, but that didn't work. I've just retested it (with the disable statement right at the very start of the macro), and it still doesn't stop AutoOpen from being triggered.

    And no, like you I can't imagine how the MsgBox would cause the problem.

    To summarise, there are four situations:
    1. <LI>If I disable auto macros AND don't have a Stop in the macro THEN I reach the Stop I've put into AutoOpen.
      <LI>If I disable auto macros AND put a Stop immediately before the MsgBox THEN the macros stop gracefully at the Stop.
      <LI>If I disable auto macros AND put a Stop immediately after the MsgBox THEN I get "cannot execute in break mode".
      <LI>If I disable auto macros AND don't have a Stop in the macro AND comment out the MsgBox THEN I reach the Stop I put into AutoOpen.
    NOTE: Facts 2 and 3 [edited later] seems to imply that MsgBox is the problem, fact 4 seems to imply it's not.
    PS: I'm running the macro directly, so it's not possible that control is being passed to another macro after the MsgBox statement.

    Confusing, eh
    Dale

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    I think that (4) rules out the Message Box as the culprit. What happens if you do (2) to pause the macro and then step through one line at a time from that point. Which line causes the AutoOpen macro to be called?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Put the Stop in the AutoOpen, otherwise you will not be able to deternine from whence it is invoked.

  9. #9
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hi Howard

    I should have made it clearer. In all four testing scenarios there was a Stop at the start of AutoOpen,

    Dale

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hi Dale
    Where is the module stored which contains the macros you forwarded?
    <UL><LI>Normal?
    <LI>An Add-In template?
    <LI>An attached template other than Normal?
    <LI>Other? (Please specify)[/list]
    Regards
    Don

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hi Don

    The macro project is in the attached template (not Normal). And it's the AutoOpen in the attached template that's being triggered.

    Dale

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hello again Dale
    It appears to me that your problem is that you SaveAs an HTML file. The problem disappears when saving as a Word document.
    I speculate--and here I seek the confirmation of more knowledgeable minds than mine--that saving to HTML requires the use of code, and in order for the process to proceed the DisableAutoMacros command is overridden.
    Regards
    Don

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Hans
    Please comment on <post#=537,562>post 537,562</post#>.
    Regards
    Don

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Don,

    It's an interesting idea, but I don't know whether it's correct or how I would be able to check that. Sorry!

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

    Re: Trapping what triggered AutoOpen (Word97/NT)

    Thanks Hans
    Regards
    Don

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
  •