Hi all I would like to control a solidworks function via an Excel file with a VBA macro
Attached is the code for the EditSuppress2() function I'm interested in. 'Dim instance As IModelDoc 'Dim value As System.Boolean 'value = instance. EditSuppress2()
Attached is the macro record via the Solidworks software 'Sub main()
Here is an example of a macro in Excel that allows you to retrieve the name of the part loaded in Solidworks:
Sub Macro1()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swApp = CreateObject("SldWorks.Application")
swApp.Visible = True
Set swModel = swApp.ActiveDoc
MsgBox swModel.GetTitle
End Sub
Don't forget to add the references to Solidworks in the Excel macro editor:
But I'm stuck on deleting a function from the part, it seems to me that I should use the EditSuppress2() function but I can't format it in VBA to remove the removal of material from my part ("Removing mat.-Extru.1@PièceX.Part")
It's that you have an object that is not defined, probably "Model".
Why do you put "@piecex. Part" after the "Enlevèv. mat.-Extru.1" in the "SelectByID" which should be "SelectByID2", as well as the "EditSuppress()" which should be "EditSuppress2()"...
Set Model = swApp.ActiveDoc boolstatus = Model.Extension.SelectByID2("Removed mat.-Extru.1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) boolstatus = swModel.EditSuppress2()
thank you for your answer but I have the same result
I'm attaching my entire code
Dim swApp As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Private Sub CommandButton1_Click()
Set swApp = CreateObject("SldWorks.application")
Set Model = swApp.ActiveDoc
boolstatus = Model.Extension.SelectByID2("Enlèv. mat.-Extru.1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModel.EditSuppress2()
Part.ClearSelection2 True
End Sub
and I still have the same error in the end "Runtime error "424": Object required