Pourquoi mes macros ne fonctionnent-elles pas dans SOLIDWORKS ?

Article by Scott Durksen, CSWE updated August 21, 2013


Starting in SOLIDWORKS 2013, a new version of Microsoft Visual Basic for Applications was introduced.  SOLIDWORKS now uses VBA 7.1 rather than VBA 6.  This new VBA version supports 64-bit systems.  As a result, your old SOLIDWORKS macros broken as they may not compile correctly with this change.

Macros SOLIDWORKS cassées

Macros SOLIDWORKS cassées

One example is Declare statements used in prior versions of SOLIDWORKS.  These Declare statements must now be marked as safe using the “PtrSafe” attribute on 64-bit systems.

Also the “Long” variable for function arguments representing pointers will require the use of the “LongPtr” variable instead.

Please refer to the following Microsoft web page for more information.

If you are using Win32 APIs, this new version also requires a change to the way you import these APIs.  Rather than making multiple versions of macros, you can use conditional compiler directives (#If Then, #Else, #End If).  This will allow the macro to work in SOLIDWORKS 2012 or 2013 in either 32-bit or 64-bit environments.  For more details and examples, please see the following forum posts.  An active SOLIDWORKS Subscription and Customer Portal account is required:

Trouver du contenu connexe par TAG :

Scott Durksen, CSWE

Scott est un ingénieur d'application SOLIDWORKS Elite et est basé dans notre bureau de Dartmouth, en Nouvelle-Écosse.