Step 2: Run the VBA Macro
Go back to the SolidWorks Interface.
Run the macro by going to Tools > Macro > Run, select SavePropertiesToExcel, and click Run.
Explanation:
SolidWorks Interaction: The script interacts with the currently active model in SolidWorks. It retrieves custom properties and mass properties like mass, volume, and surface area.
Excel Interaction: The script creates a new Excel workbook, writes the retrieved properties to the workbook, and saves it to the specified location.
Saving the File: The Excel file is saved in the specified directory with the properties listed.
Here’s an example of how you can use VBA in SolidWorks to extract information from a model (e.g., dimensions or mass properties) and save it to an Excel file.
Scenario:
You have a SolidWorks part or assembly.
You want to extract certain properties (like dimensions or mass properties) and save them to an Excel file.
Step 1: Write VBA Code in SolidWorks
Open SolidWorks and go to the VBA Editor (Alt + F11).
Insert a new module (Right-click on VBAProject (YourDocument) > Insert > Module).
Copy and paste the following VBA code into the module: