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

    Legacy References (VBA 6 Word 2K)

    Good day All

    I have a macro that has been working satisfactorily for some many months on a wide variety of Word files. Early in the process it is required to save the active document in a newly created "archive" folder as a safety precaution. The line of code that saves the file is:
    <pre>
    ActiveDocument.SaveAs FileName:=strPath & "archive" & strName, _
    FileFormat:=wdFormatDocument
    </pre>


    One particular file, when being processed raises a VBA error message at this point (Error 5180, indicating that Word cannot open a particular template). Irrespective of the warning, the file is saved. The template in question is not identified in the Word "Tools > Templates and Add-ins . . ." pull-down menu. However, it is identified as a Reference in the Project Explorer of VBA. It should be noted that on opening the original file, the user is cautioned that the file contains macros. It used to but doesn't any more.

    When working in Word and saving the file as a new document (File > Save As) with a new name, no alerts are raised, and the offending reference is purged; also on subsequent instances of opening the new file there is no caution about macros.

    It is necesssary to remove the possibility of this error message appearing but I am hesitant to insert an "On Error Resume Next" statement at this point, preferring to interrogate for unused references and purge them.

    I can't figure out how to use VBA to identify which references exist and then delete those which are unexpected. Any help wil be greatly appreciated.
    Regards
    Don

  2. #2
    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: Legacy References (VBA 6 Word 2K)

    We've had some threads on removing references at run time. It is messy and I don't recall whether any errors were raised to the user in those scenarios. Try some searches on this board and see if you can find useful code snippets to get you started.

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

    Re: Legacy References (VBA 6 Word 2K)

    Thanks Howard
    That's the case in this instance; the file was moved away from access to the template in question.
    Regards
    Don

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

    Re: Legacy References (VBA 6 Word 2K)

    When one does a Save As, in effect, you are creating a renamed copy of the document you originally opened that includes all changes made since the document was opened.

    This should cary forwar any template/project references.

    You need to look at the original do to see what template is attached and what references are included in the project.
    None of those should change in the Saved As file, unless some macro gets run during Save.

    When Word first opens a doc, it tries to resolve missing templates/references as best it can.
    However, when doing a Save As, Word is likely trying to create the same references to the current system and a reference/template might not actually exist.

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

    Re: Legacy References (VBA 6 Word 2K)

    Are you saying thge Prokect included a reference to the Access object library?
    If so, then some code is just not going to work if thje Access reference is not corrected.
    THe solution is to change the code so it no longer requires Access, then you can remove the reference to Access.

    Oh, oh, just got a knock on the door from the neighborhood watch patrol.
    They are just checking that I am following the local ordinance that requires me to watch the Red Sox-Cardinals game tonight, so I better sign off, lest I get arrested.

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

    Re: Legacy References (VBA 6 Word 2K)

    Hi Howard
    No. Access was used in the sense of accessible. The among other uses, template was used at one time to hold VBA code. Subsequently, the file was moved to a location where it could not find (access) the template.
    Sorry for the confusion.
    Regards
    Don

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

    Re: Legacy References (VBA 6 Word 2K)

    If you set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 library, you can use the References collection of the VBProject of a document. For example:

    Sub ListReferences()
    Dim i As Integer
    For i = ActiveDocument.VBProject.References.Count To 1 Step -1
    Debug.Print ActiveDocument.VBProject.References(i).Name
    Next i
    End Sub

    The loop is backwards to make it possible to delete references in the loop. This could cause problems if you looped forwards (you'd be pulling the rug from under the loop)

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

    Re: Legacy References (VBA 6 Word 2K)

    Thank You Hans
    Regards
    Don

Posting Permissions

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