• Legacy References (VBA 6 Word 2K)

    Author
    Topic
    #411469

    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:

        
        ActiveDocument.SaveAs FileName:=strPath & "archive" & strName, _
            FileFormat:=wdFormatDocument
    

    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.

    Viewing 5 reply threads
    Author
    Replies
    • #892336

      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.

    • #892337

      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.

    • #892407

      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.

      • #892467

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

        • #892473

          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.

          • #892497

            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.

          • #892498

            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.

        • #892474

          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.

      • #892468

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

    • #892408

      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.

    • #892579

      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)

    • #892580

      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)

    Viewing 5 reply threads
    Reply To: Legacy References (VBA 6 Word 2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: