AnsweredAssumed Answered

Open Top-Level SubAssembly

Question asked by Peter McCourt on Jun 1, 2017
Latest reply on Jun 1, 2017 by Deepak Gupta

I am writing a macro to create a separate BOM for each of the top-level sub-assemblies in an Assembly. The first task is to get the names of the top-level sub-assemblies, next is to open them and then output the BOM. However when I try to use either OpenDoc6 or ActivateDoc2 i get a "type mismatch" error on the *** line shown below. Any ideas as to why this might be?


Dim swApp As Object

Dim swModel As SldWorks.ModelDoc2

Dim swAssy As SldWorks.AssemblyDoc

Dim Err As Long

Dim Warn As Long

Dim Part As SldWorks.ModelDoc2



Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swAssy = swModel



Dim Components As Variant

Dim Component As SldWorks.Component2

Dim Errors As Integer



Components = swAssy.GetComponents(True)



For i = 0 To UBound(Components)



Set Component = Components(1)

Debug.Print Component.Name2



PathName = Component.GetPathName

Debug.Print PathName



swModel = swApp.ActivateDoc2(PathName, True, 0)



Next i



End Sub