
Master the Visual Basic for Applications (VBA) Editor within SOLIDWORKS . This lesson covers the essential interface mechanics from managing Project Explorer to customizing your environment ensuring you have a professional foundation before writing a single line of automation code.
Key Takeaways:
Interface Navigation: Master the "Big Four" windows: Project Explorer, Properties, Immediate, and Locals.
Real-Time Debugging: Use Debug.Print and Breakpoints to pause execution and inspect variable snapshots.
UI Fundamentals: Build simple User Forms with buttons and labels to create interactive macro tools.
Pro Customization: Optimize your IDE with specialized fonts like Cascadia Mono and custom syntax themes.
Library References: Learn to link external APIs (like Excel) to enable cross-platform automation.
Understanding data types is the most critical fundamental in programming. By choosing the correct variable type, you ensure your SOLIDWORKS macros are faster, safer, and more reliable. This lesson breaks down the built-in VBA data types , how much space they take up, and how to avoid common coding errors.
Key Takeaways:
Numeric Foundations: Understand the hierarchy of numbers, from simple Bytes and Integers to high-capacity Long and LongLong types.
Precision and CAD Math: Learn when to use Single and Double for engineering calculations and Currency to prevent rounding errors in bills of materials.
Text and Time Handling: Master the String type for file paths and names, and the Date type for timestamps and scheduling.
Memory Management: Discover how different data types occupy computer memory (from 1 to 8 bytes) and why this impacts macro performance.
Error Prevention: Identify the causes of Overflow and Type Mismatch exceptions during implicit variable conversion.
Mastering control structures is how you transform a simple script into an intelligent program. This lesson explores how to guide your code's execution using conditional logic and various looping mechanisms, essential for automating complex tasks in SOLIDWORKS.
Key Takeaways:
Conditional Branching: Master the If...Then...Else structure to execute specific code blocks based on whether a condition (like a release ratio) is met.
Looping with Certainty: Use For...Next and For Each loops when you know the number of iterations in advance, such as processing a specific list of files or an array of statuses.
Conditional Looping: Implement Do While and Do Until loops for situations where the code must repeat until a dynamic goal is reached, like a retry attempt counter.
Flow Control & Safety: Learn to use Exit For and Exit Do to break out of loops early and apply Option Explicit to prevent bugs caused by typos in variable names.
Iterative Efficiency: Understand the Step keyword in For loops to control the increment value (positive or negative) and use LBound/UBound to safely traverse arrays.
Defining Enums: Learn to create a Public Enum to represent distinct states.
The Select Case Structure: A cleaner, more efficient alternative to multiple If...ElseIf statements.
Strategic Placement: Understand where to place Enums and global variables within your module to ensure they are properly recognized by the VBA compiler.
Modular code is the key to professional automation. By breaking your SOLIDWORKS macros into smaller, reusable pieces, you make your scripts easier to debug, update, and share across different projects. This lesson focuses on Subroutines (Subs) and Functions the two primary containers for your logic.
Key Takeaways:
Subroutines (Subs): Use these to execute a series of actions (e.g. modifying a CAD property). They perform tasks but do not return a value.
Functions: Similar to Subs, but they return a specific value (e.g., calculating the sum of two numbers or checking if a file exists).
Parameters & Arguments: Make your code dynamic by passing data into your modules. You can use single or multiple parameters of any data type.
Passing by Value vs. Reference:
ByVal: Passes a copy of the data. The original variable remains unchanged outside the module.
ByRef (Default): Passes a reference to the actual variable. Changes made inside the module will affect the original variable.
Scope & Visibility: Use Public to make your modules accessible across the entire project or Private to restrict access to a single module.
Early Exits: Use Exit Sub or Exit Function to stop execution immediately if a certain condition is met, skipping any remaining code in that block.
In this lesson, we explore how to store and manage groups of information using Data Structures. We compare the three most common ways to hold data in VBA Arrays, Collections, and Dictionaries so you can choose the right tool for your specific automation task.
Key Takeaways:
Fixed Arrays: Store a set number of items using specific index positions.
Dynamic Arrays: Change size during code execution using the ReDim keyword.
Preserve Data: Use ReDim Preserve to keep existing data when resizing.
VBA Collections: Store items flexibly without needing to manually resize them.
One-Based Indexing: Remember that Collections start counting at 1, not 0.
Scripting Dictionaries: Prevent duplicate entries by using unique "Keys" for data.
Fast Retrieval: Use Dictionaries for high-speed searching in large data sets.
Early Binding: Reference "Microsoft Scripting Runtime" for better coding support (IntelliSense).
In this lesson, we show you why Class Modules are much better than Arrays for storing your data. While arrays are okay for simple lists, they quickly become a mess when you try to store complex information. We will take a messy array example and refactor it into a professional, organized class structure.
Key Takeaways:
Data Structure: Group related variables into organized, named objects instead of arrays.
State vs. Behavior: Define what an object is (properties) and what it does (methods).
Dynamic Collections: Use Collections to easily store, add, and loop through objects.
Code Readability: Use descriptive names like Car.Model to make code self-documenting.
Reliable Refactoring: Improve existing scripts by transforming them into professional, scalable projects.
In this lesson, we build a fully functional calculator using VBA UserForms. This project is a great way to learn how to design a User Interface (UI) and connect those visual elements to the underlying logic (the "Code Behind") to create interactive automation tools.
Key Takeaways:
UserForm Creation: Insert a UserForm to build custom interactive windows.
UI Controls: Use the Toolbox to add TextBoxes and CommandButtons.
Naming Conventions: Rename controls (e.g., txtDisplay) for easier coding later.
Event Handlers: Write code that triggers when a user clicks a button.
Initialize Event: Set default values (like "0") when the form opens.
Shared Subroutines: Use one "DigitPressed" routine to handle all number inputs.
Mathematical Logic: Use Select Case to manage operations like plus and minus.
Data Conversion: Convert Text (String) to numbers (Double) using CDbl.
In this lesson, we explore String Manipulation, one of the most essential skills for VBA automation. Whether you are parsing file paths, cleaning user input, or generating reports, these functions allow you to slice, dice, and transform text with precision.
Key Takeaways:
Space Cleaning: Use Trim to remove all leading and trailing spaces.
Casing Control: Use UCase for UPPERCASE and LCase for lowercase.
Extraction (Start/End): Left grabs characters from the start; Right from the end.
Middle Extraction: Mid pulls a substring starting from a specific position.
Finding Text: InStr finds a string's position; returns 0 if not found.
Reverse Search: InStrRev searches from the end (perfect for file extensions).
Search and Replace: Replace swaps specific characters or words within a string.
Arrays to Strings: Split breaks text into an array; Join puts it back.
In this lesson, we explore Error Handling, a critical skill for building professional macros that don't crash when they encounter the unexpected. Since bugs are an inevitable part of development, learning how to "catch" them ensures your tools remain reliable and user-friendly.
Key Takeaways:
Runtime Errors: These occur during execution (e.g., division by zero) and stop your code unless handled.
On Error GoTo: Redirects the code to a specific "Handler" section when a bug occurs.
The Err Object: Use Err.Number and Err.Description to identify and explain the specific problem.
Exit Sub: Always place Exit Sub before your error handler to prevent it from running during normal execution.
On Error Resume Next: Tells VBA to ignore the error and immediately move to the very next line of code.
Clean Up: Use error handlers to ensure your macro closes files or turns settings back on even if it crashes.
In this lesson, we explore how to use Win32 API calls to extend the capabilities of your macros. Sometimes, the SOLIDWORKS or PDM API doesn't have the specific command you need like maximizing a window and that is where the Windows operating system libraries come in to bridge the gap.
Key Takeaways:
Beyond the Host: Use Win32 APIs to perform tasks not supported by SOLIDWORKS or Office.
Window Handles (hWnd): Every window has a unique ID used by Windows to identify it.
PTRSafe Declarations: Use Declare PtrSafe to ensure your API calls work on 64-bit systems.
External Libraries: Access professional-grade functions from system files like user32.dll.
ShowWindow Function: Use this specific API to control window states like Maximize or Minimize.
LongPtr Type: Always use LongPtr for handles to stay compatible with modern hardware.
In this course, you will learn how to navigate and master the Visual Basic for Applications (VBA) Editor.
This course does not cover any specific APIs like SOLIDWORKS, AutoCAD or Excel but rather focuses on the VBA programming language itself.
You will start by learning the mechanics of the interface, including the Project Explorer, Properties, Immediate, and Locals windows, and how to customize your environment for a professional setup. You will learn the importance of data types, covering numeric foundations.
The course teaches you how to manage memory, handle text and time data, and avoid common errors such as overflows and type mismatches.
You will also learn how to use control structures, including If...Then...Else logic, Select Case statements, and various looping mechanisms like For...Next and Do While to make your scripts more intelligent.
The lessons cover modular programming, where you will learn to create reusable Subroutines and Functions, pass arguments by value or by reference, and manage code visibility using Public and Private scopes.
Additionally, you will learn to manage complex data using Arrays, Collections, and Dictionaries, as well as how to refactor your code into Class Modules for a more organized structure.
You will learn to design interactive UserForms with custom controls like textboxes and buttons, and how to write event handlers to connect your UI to your logic.
Finally, the course covers advanced string manipulation, robust error handling to prevent macro crashes, and the use of Win32 API.