Choose which version of SolidWorks to open via Excel (2021 or 2022)

Hi all

I have a macro that I launch via an Excel nomenclature. It allows me to modify the properties of parts and assemblies and to save plans in PDF and DXF as well as parts in STEP to prepare my manufacturing files. I would like to point out that when running the macro, you don't see SolidWorks open or the parts/planes open and close.

But here's the thing, my problem is that we are working with the 2022 version and one of our customers is working with the 2021 version and installing a working environment for their version of SolidWorks on our workstations.

So my question is the following: can we choose from Excel which version of SolidWorks to open (I would do this via a UserForm I think)? My knowledge of VBA is limited, everything I've done so far I've done by picking right and left on the internet. For the part of code specific to SolidWorks commands (the part modifying properties is not quite finished yet, I don't put it below):

Opening SolidWorks:
Set SWAPP = CreateObject("SldWorks.Application")

Opening and recording of the piece in STEP:
Set SWMODEL = SWAPP. OpenDoc6(CHEMIN_PIECE, 1, 1, "", myError, myWarning)
SWMODEL. SaveAs2 FLD_LANCEMENT_TEMPO & CHEMIN_STEP, 0, True, False

Opening and saving the plan in PDF and DXF:
Set SWMODEL = SWAPP. OpenDoc6(CHEMIN_PLAN, 3, swOpenDocOptions_Silent, "", myError, myWarning)
SWMODEL. SaveAs2 FLD_LANCEMENT_TEMPO & CHEMIN_PDF, 0, True, False
SWMODEL. SaveAs2 FLD_LANCEMENT_TEMPO & CHEMIN_DXF, 0, True, False

Closing open documents:
SWAPP. CloseAllDocuments True
Set SWAPP = Nothing: Set SWMODEL = Nothing

Can we instead of the "Set SWAPP = CreateObject("SldWorks.Application")" have a line of code that allows you to open the desired version?

Thank you for your help =)

Hello @f.vergneau ,

To choose the version of SolidWorks, simply add the version hint to the end of the SWAPP object's creation text:
Set SWAPP = CreateObject("SldWorks.Application.30")

Be sure to put the appropriate quotation marks, and no spaces.
The clues are as follows:

  • SOLIDWORKS 2015: 23
  • SOLIDWORKS 2016: 24
  • SOLIDWORKS 2017: 25
  • SOLIDWORKS 2018: 26
  • SOLIDWORKS 2019: 27
  • SOLIDWORKS 2020: 28
  • SOLIDWORKS 2021: 29
  • SOLIDWORKS 2022: 30

You can suggest the choice of version in a drop-down list, and retrieve the correct index from its ListIndex property.
image

Kind regards.

3 Likes

Hi m.blt!

Thank you very much for your answer, it works perfectly! What efficiency :wink: !