Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto code and Missing References (Word 2002 VBA)

    Hi, all.

    I have a type of document that contains code modules. There is a Document_Open routine, a routine that will scan for and delete any missing Project references, and a class module that responds to the user's mouse-clicks in the document. (I am attaching copies of the code.) All of these are supposed to kick in automatically when the file is opened.

    At any rate, when there is a missing reference, that reference is successfully removed; but I also find that the "mouse-click-code" doesn't initialize (pardon me if I'm using the wrong term here.) After a missing reference is removed, I must "re-run" the line "Set MyClass.app = Application" for the sub Private Sub app_WindowSelectionChange(ByVal Sel As Selection) to kick in, and (here's the problem) that only seems to work if I run it "stand-alone," that is, after the Document_Open event/code have finished. If I put it in an error handler or even if I run it as the last line of the "CheckReferences" code, it has no effect. It only works if I run it after all other code has finished. The problem with this, of course, is that the document protection (which hinges on the app_WindowSelectionChange routine mentioned above) doesn't take effect and the user can edit whatever parts of the document they want. (It might also be worth mentioning that, if I save and close the document after the missing reference is removed, all code works fine when I subsequently re-open it.)

    I can't throw up a dialog box in these situations, because this document is part of a larger, unattended process. I'm in a bind. Any suggestions?
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

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

    Re: Auto code and Missing References (Word 2002 VBA)

    I have always found broken references very tricky to deal with in code.

    You state that the document works fine once the broken references have been removed (and the document has been saved, closed and reopened). That makes me wonder why the references are there at all. Wouldn't it be better to distribute the document without unneeded references?

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

    Re: Auto code and Missing References (Word 2002 VBA)

    As you have found, the only way to avoid errors with missing references is to explicitly indicate the library to which each function etc. belongs. This becomes very tedious, but I don't know of another way.

    You could try setting the AttachedTemplate to Normal. Since Word always has (or should have) access to Normal.dot, that should not cause problems.

    I'm afraid I have no further suggestions.

  4. #4
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto code and Missing References (Word 2002 VBA)

    Ahh, if only... There are actually two kinds of unavoidable references that I'm dealing with in this case. One is a reference to the document's template. The other is a bogus reference to various ~tmp files, which I believe are introduced unintentionally by an automated procedure.

    Because my explaination is a tad long (but I think it's concise!) I'm attaching it to this message.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

Posting Permissions

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