You need to be logged in to view this content. Please login or become a member.


This presentation was given at SolidWorks World 2012 in a hands-on session called “Taking Macros to the People: Hands-On For Beginners”. The advertised description: “Forget abstract talks about object-oriented programming. This hands-on class will get the total beginner on track to unleash the SolidWorks API for greater productivity, using quick and dirty tactics involving the macro recorder, API help, and free cheat sheets.”


Common VBA variable data types used with the SolidWorks API:

Common variable data types


Notes (handout)
Create extruded base with user form



    I’m working thru this video and immediately after recording my macro…
    I get this when I try to run it:
    “Run Time Error ’91’:” and “Object variable or With block variable not set”
    I’m at 5:54 into the video (for reference).
    I have tried debugging this, but I obviously don’t know enough VBA yet.
    I’m running:
    Windows 7
    SolidWorks 2012 SP4.0
    Microsoft VBA 7.1

    Please and Thank You…

    • Hi,

      This error usually occurs when you try to use a function on an object that is Nothing or when you forget to use the Set keyword when setting an object variable’s reference. Of course, in your case, you are using the macro recorder so it is the macro recorder that messed up, not you.

      Since this is a very common error, I address it at the end of this blog post: Debugging Tips for VBA Programmers


  2. Singhsons


    Is that possible to make a link between file property of a solidworks document(where we enter the description, part number and other detail related to part or assembly or drawing) with the excel file.
    basically, we have a register (excel) from where we raised the part number for the part. what i am trying to do is, if i fill the part detail in solidworks file property then it automatic write the description in register. so we dont need to type same detail in register.

    can you please guide me to do this. if you not understand what i am trying to expain please let me know.


    • Hi Singh,

      I have a blog post on how to connect the SolidWorks and Excel APIs that will allow you to do this. Please see that here. The interface you need to work with SolidWorks custom properties is ICustomPropertyManager. There are lots of examples in the API Help.

  3. api_learn_tg


    i’d like to make some Macrobuttons to open SW-Assemblies juste by one click, the same way then => File =>Open => (usually browse the Filepath ) => OK (Open).

    Which is the code that i use ? Is there an example ?



  4. Mnafornita

    Even if I declared…
    Dim swApp as SldWorks.sldworks
    when I type swApp. the drop-down list with the members of the object does not appear. Does anybody knows why.? It’s a option somewhere in the IDE?

Questions and Comments

You must be logged in to post a comment.