Error 91; macro that no longer launches

Hello

I use a macro to generate my BOM and my macro no longer launches.

I have a bug at the beginning.

Excell opens but I mess with the statement "Set swModelDocExt = swModel.Extension"

I don't understand because it worked very well until then...

Could you help me identify the problem please?

thank you in advance

 

LSE

 

 

Option Explicit

Sub main()

Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Dim wbk As Excel.Workbook
Dim sht As Excel.Worksheet


Dim swApp                   As SldWorks.SldWorks
Dim swModel                 As SldWorks.ModelDoc2
Dim swModelDocExt           As SldWorks.ModelDocExtension
Dim swBOMAnnotation         As SldWorks.BomTableAnnotation
Dim swBOMFeature            As SldWorks.BomFeature
Dim boolstatus              As Boolean
Dim BomType                 As Long
Dim Configuration           As String
Dim TemplateName            As String
Dim TableTemplate           As String
Dim sFileName               As String
Dim Dossier_Nomenclature    As String
Dim Repertoire              As String
Sun Repertoire_Test         As Boolean
Dim Fichier_ouvrir          As Thong
Dim fichier_complet         As Thong
Dim myError                 As Integer
Dim myWarning               As Integer
Dim Nom_Fichier_Excell      As Variant
Dim Path                  As String
Dim Fichier_section_source  As String


Opening an Excell sheet

With xlApp
    . Visible = True
    Set wbk = . Workbooks.Add
    Set sht = wbk. ActiveSheet
End With

' Retrieving Assembly Information

Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

sFileName = swModel.GetPathName '= display name of the assembly with the path
Debug.Print sFileName

 


2022-04-08_15h58_44.png

I've already encountered problems with this line (the following error may stem from this):

Set swApp = GetObject(, "SldWorks.Application")

To be replaced by

Set swApp = Application.SldWorks

Otherwise you have to look in your local variables e, launching the macro step by step (F8)

 

Do you have the rest of the macro I don't have the problem (SW2020)

Otherwise look at this topic the version is perfectly functional at home (after changing the path of the nomenclature template)

https://www.lynkoa.com/node/1130889

After testing it, if you use it to correct yours, there's no reason why it shouldn't work as well.