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 :
<p>Private Sub CommandButton1_Click()</p><p><br>Dim longstatus As Long<br>Dim longwarnings As Long<br>Dim swApp As SldWorks.SldWorks<br>Dim swPart1 As SldWorks.ModelDoc2<br>Dim swPart2 As SldWorks.ModelDoc2<br>Dim swPart3 As SldWorks.ModelDoc2</p><p></p><p>On Error Resume Next</p><p></p><p>Set swApp = GetObject(, "SldWorks.Application")</p><p><br>If Err.Number = 0 Then<br>Else<br> If MsgBox("Veuillez lancer Solidworks avant d'ouvrir la MEP.", 0 + 4096 + 48, "Attention") = True Then<br> End If<br> Exit Sub<br>End If</p><p></p><p>Set swPart1 = swApp.OpenDoc6(PathCinderblock, 1, 0, "", longstatus, longwarnings)<br>DoEvents<br>Set swPart2 = swApp.OpenDoc6(PathPlank,1, 0, "", longstatus, longwarnings)<br>DoEvents<br>Set swPart3 = swApp.OpenDoc6(PathASM, 2, 0, "", longstatus, longwarnings)<br>DoEvents<br>End Sub</p>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.
SolidworksApi macros