Results 1 to 7 of 7
  1. #1
    bfreer
    Guest

    correction for missing references in many docs

    I have a VBA problem. At my company, a very large number of Word97 SR-2 documents have been created with simple VBA macros that partially automate the documents. However, when the docs are moved outside the company system, and a user attempts to run the automation macro a VBA compile error "Can't Find Projet or Library" presents itself. It turns out that the missing reference is a single template on which all these docs were based. However, unchecking the reference (via references from the tools menu in the VBA editor) corrects the problem and the code still compiles fine. What I am trying to figure out is a way to be able to make this change in one mass effort without having to open and edit each of the several hundred form documents.

    Any ideas?

    Brant Freer

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

    Re: correction for missing references in many docs

    Why not just create a replacement template. If deleting the reference to the template lets your stuff "keep on workin'", then creating a fake template with no contents should achieve the same result.

    I have similar problems when, for example, WordPro says it can't find an AmiPro template i had years ago. I just create a new one, give it the misisng name, and hear no more about it.


    You'll have to create a template rather than a document (File, New, click on the Template button) and you'll have to save it in whatavere folder Word97SR2 expects to find it.

    If you're not sure of where that is, inspect Tools, Options, File Locations.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: correction for missing references in many docs

    <P ID="edit"><FONT SIZE=-1>Edited by Gary Frieder on 01/02/28 10:54.</FONT></P>Hi Brant,

    It's possible to create a macro to cycle through hundreds of documents, open them, make changes, save and close them.

    It's also possible to unset a reference in the VB Editor, programatically (thanks Jefferson!).

    But before doing that, I'm wondering if I'm not understanding the problem correctly:

    Aren't the references which need to be removed, set in the templates upon which these documents are based, rather than in the documents themselves?
    Because if the former is the case, it shouldn't require automation to go into a few templates and turn off the reference manually.

    If the latter is the case, then we can knock together a macro out of spare parts.

    So can you provide just a little more detail as to where and how these references are presently set?

    Gary

    Added a PS: This part
    <hr>However, when the docs are moved outside the company system, and a user attempts to run the automation macro a VBA compile error "Can't Find Projet or Library" presents itself. It turns out that the missing reference is a single template on which all these docs were based. However, unchecking the reference (via references from the tools menu in the VBA editor) corrects the problem and the code still compiles fine<hr>
    has got me a little lost:
    If the code resides in the templates that the documents are based on, rather than in the documents themselves, then when the docs are moved outside the company system, the outside users shouldn't be able to run the associated macros at all (nor see them).
    So it's unclear where the error message is arising from: is the code actually attached to the document, rather than the template? Or are you sending out the document and the template as well?

    And is it actually the outside user who is going in and unchecking a reference in the VB Editor? Again, if the reference is localized to the attached template, which doesn't normally travel with the document when you send it outside, then the outside user normally wouldn't even see the reference turned on on their machine.

    So some more details would be helpful.

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: correction for missing references in many docs

    Are all the documents in a single directory? If so, you can loop thru the directory and remove the reference from each document. First, get the name of the reference you want to remove by looking in Tools|References in one of the documents you want to fix. In a new document, do something like this:

    Sub RemoveReference(DirToScan as String, RefToRemove As String)

    'Send Directory name with trailing .
    'Send name of reference as seen in Tools|References list.

    Dim MyDoc as Document
    Dim i as Integer
    Dim DocName as String

    DocName = Dir$(DirToScan)

    Do While DocName > ""

    Set MyDoc = Documents.Open(FileName:=DirToScan & DocName)

    With MyDoc.VBProject

    'Find the reference, remove.
    i = .References.Count
    Do While i > 0
    If .References(i).Name = RefToRemove Then
    .References.Remove .References(i)
    End If
    i = i - 1
    Loop

    End With

    MyDoc.Save
    MyDoc.Close

    Set MyDoc = Nothing
    DocName = Dir$

    Loop

    This should loop through each file in the desired directory, and remove the desired reference from each document. It assumes that only the documents you want to fix are in the particular directory.
    You MAY have to add a reference to the VBA Extensibility library in the document that contains this routine.
    Feel free to e-mail me with any questions.

  5. #5
    bfreer
    Guest

    Re: correction for missing references in many docs

    Wow! Thanks for the code. I will give that a try. Almost all the effected documents are in the same directory.

    Brant Freer

  6. #6
    bfreer
    Guest

    Re: correction for missing references in many docs

    Thanks so much. This is a great work-around. I still plan to eventually fix the problem, but this will get us a long way there for now.

    Brant Freer

  7. #7
    bfreer
    Guest

    Re: correction for missing references in many docs

    Here is some more detail, as if there was a single doc instead of many. The macro is in a document, not a template. The document is stored on an intranet site. When a user clicks a link to retrieve the document (with the macros in it), the document opens fine. But when the user runs the macro, the macro crashes out with error I described. It is clear that the macro is looking for a resource which happens to be the template on which the document was based. The error occurs where that user does not have access to the template.

    Hope that helps.

Posting Permissions

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