AnsweredAssumed Answered

Problem opening an asm driven by a design table

Question asked by Simon Dubois on Sep 30, 2015
Latest reply on Oct 6, 2015 by Simon Dubois

Hellow !

 

I'm trying to open an asm in VBA (from an external excel file).

This asm is driven by a design table to put some cinderblock on a plank.

The plank is driven by a design table to set its dimensions.

The cindeblocks are driven by design table to set their dimensions.

 

When I try to open the asm, solidworks automatically :

- opens the asm, opens its design table, closes its design table.

- opens the plank, opens its design table, closes its design table, updates the plank.

- opens the cinderblocks, opens their design table, closes their design table, updates the cindeblocks.

- update the asm.

 

The problem is : Because of opening all these excel file while a macro is running in another one, 7 out of 10 times it crashes.

 

Here is the code :

 

Private Sub CommandButton1_Click()


Dim longstatus As Long
Dim longwarnings As Long
Dim swApp As SldWorks.SldWorks
Dim swPart1 As SldWorks.ModelDoc2
Dim swPart2 As SldWorks.ModelDoc2
Dim swPart3 As SldWorks.ModelDoc2

 

On Error Resume Next

 

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


If Err.Number = 0 Then
Else
    If MsgBox("Veuillez lancer Solidworks avant d'ouvrir la MEP.", 0 + 4096 + 48, "Attention") = True Then
    End If
    Exit Sub
End If

 

Set swPart1 = swApp.OpenDoc6(PathCinderblock, 1, 0, "", longstatus, longwarnings)
DoEvents
Set swPart2 = swApp.OpenDoc6(PathPlank,1, 0, "", longstatus, longwarnings)
DoEvents
Set swPart3 = swApp.OpenDoc6(PathASM, 2, 0, "", longstatus, longwarnings)
DoEvents
End Sub

 

At the beginning, I tried directly opening the ASM, and opening solidworks with Set swApp = New SldWorks.SldWorks, it worked sometimes, but it seemed to crash even more frequently.

 

So I tried how it is above. But again, it crashes frequently.

 

Does someone have a solution to this problem ?

 

Thank you,

 

Simon

 

PS : Don't mind my English, I'm not very good at it.

Outcomes