VBA Excel for SolidWorks

Hi all

I'm looking to create a VBA code in Excel that allows me to launch Solidworks, open a SolidWorks part or assembly file and modify the properties of this file.

Having no knowledge of SW macros. I've done a lot of research on the web, but I can't open a file.

Thank you in advance.

Have a nice day.

Hello

I think I had made one but I can't get my hands on it!

Otherwise look at this link:

https://forum.solidworks.com/thread/69618

But a priori Excel opens a SolidWorks document (but not SolidWorks directly):

  'Link to Solidworks

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

  If swModel Is Nothing Then

        MsgBox "No document loaded" & vbCrLf & _

                "Open a Solidworks Drawing first!", vbMsgBoxSetForeground + vbSystemModal

    Else

'... Continuation of the code

1 Like

And of course don't forget to include the SolidWorks references in Excel, otherwise you can't do anything at all!

See this link:

http://www.cadsharp.com/blog/using-microsoft-excel-with-the-solidworks-api/

More specifically this part:

Once the macro has been created in Excel, go to "Tools > References" and check:

 "SldWorks 20XX Type Library"

 

1 Like

Thank you .PL for these quick answers.

The links are interesting

I don't understand my problem. If, for example, I use the code from the example of the second link to display a message in SW does not compile:

Dim swApp As SldWorks.SldWorks

See attachment.

Thank you.


capture.jpg
1 Like

Thank you .PL.

Indeed, we had to add the "SldWorks 20XX Type Library".

Now SW codes work.

I will keep you informed of the rest.

Thank you.

1 Like

Regarding the changes to the properties, I advise you to look at the macro I posted as a tutorial on Lynkoa:

http://www.lynkoa.com/tutos/3d/macro-enregistrer-sous-avec-solidworks

This macro, where each line is commented out, modifies properties (including the code property).

For example, to assign a property:

CODE = SWmoddoc.CustomInfo("code")

To add a property:

retval = SWmoddoc.AddCustomInfo3("", "CODE", 30, NewCode)

1 Like

I manage to open the room and change the properties.

Thanks to Lucas...

1 Like