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
If MsgBox("Veuillez lancer Solidworks avant d'ouvrir la MEP.", 0 + 4096 + 48, "Attention") = True Then
Set swPart1 = swApp.OpenDoc6(PathCinderblock, 1, 0, "", longstatus, longwarnings)
Set swPart2 = swApp.OpenDoc6(PathPlank,1, 0, "", longstatus, longwarnings)
Set swPart3 = swApp.OpenDoc6(PathASM, 2, 0, "", longstatus, longwarnings)
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 ?
PS : Don't mind my English, I'm not very good at it.