Why Excel Macros Are Good for Your Electrical Design

   By Adam Ferrer on April 10, 2023

What are SOLIDWORKS Electrical Macros?

An Electrical Schematic Macro is a part of scheme that you have already drawn, and you want to re-use in another drawing or another electrical project. Macros are stored in a library. Several types of macros exist, such as scheme macros, line diagram macros, project macros, or PLC macros.

excel macros for solidworks electrical


What exactly is Excel Automation? This feature allows users to generate schematic drawings from data contained within an Excel file. Basically, users can create and customize an Excel file based off a standard design and then generate new designs based off that configuration. Once the Excel file is created users can modify data in Excel as project data changes and have those modifications updated for new projects within SOLIDWORKS Electrical. Excel Automation can be used to create books, folders, and drawing files.

Who benefits from this?

The best candidates for Excel Automation are those who have design projects that are similar in nature and utilized frequently.  

Electrical Macros

Here when talking about “macro” it means macro from electrical project, not to be confused with VBA macro that is the script you can use in Excel to reproduce a sequence of actions.

In Excel file, the user will specify:

  • Macro to insert.
  • Where to insert macro: book, drawing, and coordinates in drawing.
  • Set general information about book, drawing, location, function.
  • Set values for macro variables.

For this to succeed, the macros must be edited, especially to define variables.

Macro variables

When the user saves a macro, they can edit it and define some “variables” in order to modify the characteristics of the macro before insertion from Excel file.

Variables are surrounded by % character with no specific limit on the name. It is recommended to avoid whitespace like %My variable% and use explicit variable names %CableMark% better than %Variable1%.

macro variables for excel files using SOLIDWORKS

macro variables in excel for SOLIDWORKS

When editing the macro, the user will modify object property to set the variable to be able to replace by the value according to information described in Excel file.

One variable can be used several times in a macro but should be used for the same information.

Variables can be used also for any object that has a mark for:

  • Description
  • Translatable data
  • User data

Variable for manufacturer reference

For manufacturer parts, the user needs to define at least one or two variables:

  • For reference only, for existing manufacturer
  • For reference and manufacturer, to be able to choose any part.

Using edit on part properties, variables must be set for Reference and/or manufacturer.

When editing macro to set variable on a manufacturer part, it would be useful to ensure the attributes for manufacturer parts are visible to show the variable names.


Practically, to be able to generate custom drawing from Excel, the user needs to:

  • Save macros corresponding to the part of drawing.
  • Edit macros to set variables for macro values to be replaced at inserted.
  • Define an Excel template with the format he wants to use and the necessary information to define macro to insert.

Once this preparation work is done, user can create new Excel file from template, fill the content to define which macros to insert and generate drawings.

From ribbon menu, in Import/Export tab, two main features are available for Excel automation.

  1. Creation of a new Excel file from a predefined template
  2. Generation of drawings from an Excel file.

excel automation ribbon

The supported file extensions are:

  • .xlsx – Excel Workbook
  • .xlsb – Binary Excel workbook
  • .xls – Excel 97-2003 workbook
  • .xlsm – Excel workbook with VBA Macros

Macro definition fields

The fields for macro definition will give instructions about the macro to insert:

  1.  Macro name
  2. Coordinate of macro insertion, in drawing units.

fields for macro definition will give instructions about the macro to insert

Database fields

Database fields are optional fields corresponding to data from project database. They are usually named as the field in the database table. Only the fields from the following tables are supported.

database fields for SW Electrical design

Create new Excel File for Automation

This feature will look for Excel template and propose to create one new file, copying the selected template.

Once a template is selected, the user is asked for destination of new file, then it is open to let user fill the file for generating drawings.

Notice the template already has columns created with variable names already defined (these can be changed; just ensure they are the same when defined in the Electrical Macros).

template already has columns created with variable names already defined template already has columns created with variable names already defined

Template’s location:

The templates listed are the Excel files existing in the folder “XlsAutomation\Template” from application data folder. The user is free to copy and modify the existing templates to create one with the formatting and the details he wants.

Generation of Drawings

When the user clicks on button Excel automation, the user is asked to select an Excel file describing macros to be inserted. Once validated, process is started, and generation of drawings begins. In the end, a report is displayed to inform about possible errors or warnings.

Below is an example of a populated excel template built off the original template.

Excel template built off original template with colored columns

The program will read the fields from excel and generate our schematic by matching the variables and Electrical Macros from the worksheet to the project. Then write the content from the variable fields to the corresponding macros.

electrical design using excel automation

To learn more about how you can take advantage of this form of automation in your electrical design process, reach out to our team and we can work with you to get your projects streamlined and your products out the door faster.

Related Products

Browse the TriMech web store for SOLIDWORKS software to design, analyze and manufacture your products on your desktop.

Adam Ferrer

Related Content

Graco Hand Tool

Graco: Nylon 3D Printed Pressure Check Hand Tool

Graco Inc. supplies technology and expertise for the management of fluids and coatings in both…

Learn More...

What are the differences between P3 and CLIP 3D printing technology?

P3 vs CLIP As 3D printing continues to evolve and revolutionize the manufacturing space, the…

Learn More...

Creating Lofts in SOLIDWORKS

Part modeling in SOLIDWORKS can go far beyond what our imagination is able to create….

Learn More...