I'm currently creating a macro from an excel file to work on Solidworks, it's fine with me at the moment. My macro just creates an assembly and inserts some component.
To avoid any problems with updates and reading/writing of other users I would like to write this macro on solidworks but launch it from excel. This way I can update it every day and it will take effect immediately, which will not necessarily be the case on excel.
I found some draft answer but it remains in the excel application, the application launches the macro of a workbook that is closed, example below.
Sub TestRun()
Application.Run "'C:\Users\franck\Desktop\Classeur1.xlsm'!Module2.Macro2"
End Sub
Otherwise I also have another solution, put the "useful" macro in another file and run it like that, it will allow me to update the file easily and I won't have to look for how to launch a Solidworks macro from an Excel macro.
Here's sample code to launch SolidWorks from Excel:
Sub LancementSW()
Dim SW_App As New SldWorks.SldWorks
Dim SW_Doc As SldWorks.ModelDoc2
Dim Result As VbMsgBoxResult
SW_App.Visible = True
Result = MsgBox("Test réussi.", vbInformation + vbOKOnly, "Test")
End Sub
You must first add the reference "SldWorks 2018 Type Library" to your project