Listing documents open in Inventor with VBA

Top  Previous  Next

Here is some VBA code to do that to the VBA editor window. It also lists the documents inside the top level documents:


Option Explicit


Public Sub ShowDocuments2()


    ' Get the Documents collection object.

    Dim invDocs As Documents

    Set invDocs = ThisApplication.Documents

    Dim sExt As String


    ' Iterate through the contents of the Documents collection.

    Dim invDocument As Document

    Dim SubDoc As Document


    Dim Asm As AssemblyDocument

    Dim DocsInAsm As DocumentsEnumerator

    For Each invDocument In invDocs

        ' Display the full filename of the document in the Immediate window.


        sExt = Right(invDocument.FullFileName, 3)


        If sExt = "IAM" Then

             Set Asm = invDocument

             Set DocsInAsm = Asm.AllReferencedDocuments

             Debug.Print "Assembly " & invDocument.FullFileName & " has " & DocsInAsm.Count & " sub documents"


             For Each SubDoc In DocsInAsm

                 Debug.Print "   SubDoc " & SubDoc.FullFileName


        End If        



End Sub



Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)