File format · .swp
SolidWorks Macro (.SWP) File Format and Repair Guide
A reference guide to the SolidWorks .swp macro file format: what it stores, how VBA projects are structured, why macros fail, and how code is recovered.
SolidWorks, the 3D mechanical CAD platform developed by SolidWorks Corporation (founded in 1993 and part of Dassault Systèmes since 1997), ships with a full programming API, and the most popular way to use it is the macro: a small program, usually written in VBA, that automates repetitive design work. Macros are stored in .swp files, a format that is surprisingly easy to lose to a crashed editor, a cloud-sync glitch, or a version upgrade. This guide explains what SWP files are, how they are built, why they stop loading, and what can usually be recovered when one is damaged.
What a SolidWorks Macro Is
A SolidWorks macro is a saved program that drives the CAD application through its documented, COM-based API. Users create macros in several ways: by recording actions with Tools > Macro > Record, which captures the equivalent API calls as VBA code; by writing code by hand in the built-in VBA editor (Tools > Macro > Edit); or by adapting established sample code. Running a macro (Tools > Macro > Run) presents a list of the procedures the file contains, and frequently used macros can be attached to toolbar buttons, keyboard shortcuts, and mouse gestures.
Typical automation includes batch exporting drawings to PDF or DXF, writing custom properties, generating standard features or parts, renaming configurations in bulk, and enforcing drawing standards. Because the API reaches every document type (parts, assemblies, and drawings), macros often become business-critical: losing a mature macro file can mean losing years of accumulated process knowledge.
Models can also contain macro features, custom features whose rebuild behavior is defined by macro code. If the macro file a macro feature points to is missing or damaged, the feature fails to rebuild, so a broken SWP file can affect the documents that reference it, not just the macro itself.
The SWP and SWB File Formats at a Glance
Key facts, with the caveat that Dassault Systèmes' own documentation is authoritative for exact internals:
- Full name: SolidWorks macro file
- Extensions: .swp (current format) and .swb (a legacy format from early SolidWorks releases; current versions can open legacy files and re-save them as .swp)
- Developer: SolidWorks Corporation, today Dassault Systèmes SOLIDWORKS Corp
- Category: script and automation container
- Container: a Microsoft compound document (OLE structured storage), the same container family used by legacy Office documents
- File signature: compound document files begin with the bytes D0 CF 11 E0 A1 B1 1A E1
- MIME type: none is registered specifically for this format
- Contents: a complete VBA project: standard modules, class modules, UserForms, and the project's reference list
Internally, the compound document works like a miniature file system of storages and streams. The VBA project occupies its own storage, with module source code held in compressed streams, consistent with Microsoft's published VBA project format documentation. The project also carries references to the SolidWorks type libraries (the application library and the constants library) installed alongside the software. Those references are version-specific, which matters for compatibility, as covered below.
Two neighboring technologies are worth distinguishing. Add-ins are compiled DLLs built on the same API; they are not macros and follow different packaging. Depending on the release, SolidWorks has also offered VSTA macro projects written in .NET languages alongside classic VBA. One identification caution: the .swp extension is also used by the Vim text editor for its swap files. A Vim swap file is an entirely different artifact, typically created alongside an edited file (for example .notes.txt.swp) and recovered with Vim's own crash-recovery command, not with CAD tooling.
Why SWP Macro Files Become Corrupt or Unreadable
- Interrupted saves. If SolidWorks or the VBA editor crashes, or power is lost while the project is being written, the compound document can be left half-written, with an inconsistent internal allocation table.
- Network and cloud-sync storage. Running or saving macros directly from network shares, or from folders managed by sync clients such as OneDrive or Dropbox, exposes the container to partial rewrites and sync conflicts. This is one of the most common real-world causes of damage we see.
- Failing media. Bad sectors or flash wear corrupt the container's header or internal tables, stranding otherwise intact streams.
- Version mismatch. Macros saved by a newer SolidWorks release generally cannot be opened in older releases, because the embedded project references type libraries the older installation does not have. The file is healthy; the environment is not.
- Broken references after upgrades. After moving to a new release, or uninstalling an old one, references can point at libraries that no longer exist, producing compile errors such as undefined types. This looks like corruption but is a repairable configuration problem.
- 64-bit VBA migration. When SolidWorks moved to 64-bit VBA, macros containing Windows API declarations needed code updates; older macros can fail to compile on current releases for this reason alone.
- Antivirus and macro blocking. Security software may quarantine or strip VBA content heuristically, and macro security policies can silently prevent loading, which mimics a broken file.
- Lost project passwords. VBA projects can be locked from the editor; losing the password locks the owner out of their own code.
- Mistaken identity. A file that is actually a Vim swap file, a partial download, or a renamed attachment will not open in SolidWorks no matter how healthy it is.
Typical symptoms include SolidWorks reporting that the file is not a valid macro, the VBA editor opening to an empty project or missing modules, individual modules failing to import, or the code compiling with a cascade of reference errors.
What Can Be Recovered from a Damaged SWP File
In most cases, a great deal, because the source code is the payload:
- VBA source code from standard modules, often in full, even when the file no longer opens in the editor
- Class module code
- UserForm definitions: control layouts, properties, and the code behind them
- The project's structure: component names and the reference list needed to rebuild it
- Partial code when damage is severe: undamaged streams are extracted individually
- Legacy .swb content, via conversion to the current format
Honest limits apply. If the file was overwritten, or was deleted with no backup, there is nothing to extract from the file itself, and recovery then depends on backups, previously exported module copies, or the macro's original author. We always tell you plainly which situation you are in before any work is done.
How SolidWorks Macro Recovery Works
- Work on a forensic copy. The damaged original is never touched.
- Identify the file. Confirm it is a compound document macro rather than a Vim swap file or other look-alike.
- Assess the container. Check the header and internal tables to determine which storages and streams survive.
- Extract at stream level. Parse the compound document, locate the VBA project storage, and decompress the module streams using the documented VBA compression scheme to recover readable source text.
- Rebuild. Import the recovered modules, class modules, and forms into a fresh macro file, restore references to the type libraries of the SolidWorks release in use, and re-apply project protection where the owner requests it.
- Validate. Compile the project and run it against a test document, so it comes back working rather than merely present.
Prevention is cheaper than repair. Export modules regularly from the VBA editor as plain .bas, .frm, and .cls files, which are text and survive almost anything. Keep macro files on local disks with real backups, edit a copy rather than the live file, and note which SolidWorks version each macro was last saved under.
FAQ
What is an SWP file?
An .swp file is a SolidWorks macro: a compound document container holding a VBA project that automates SolidWorks through its API. A related .swb extension was used by early SolidWorks releases and can be converted to the current format.
Why won't my macro load in SolidWorks?
The most common causes are container damage from an interrupted save or sync conflict, a version mismatch (the macro was saved by a newer release), broken type library references after an upgrade, or a security tool blocking VBA content. Each has a different fix, so identification comes first.
Can an older SolidWorks release open a macro saved by a newer one?
Generally no. The embedded project references the newer release's type libraries. Keep a copy of important macros saved under the oldest release you still need to support, or store the code as exported text modules.
My macro opens but the modules are empty. Is the code gone?
Not necessarily. Empty or missing modules usually mean the streams holding that code were damaged or stripped, while other parts of the container may still be intact. Stream-level extraction often recovers source that the editor cannot display.
Is a SolidWorks SWP file the same as a Vim swap file?
No. They share only the extension. Vim swap files are created by the Vim editor while a text file is being edited and are recovered with Vim's own recovery command. Checking the file's signature and structure settles the question quickly.
Can a password-protected SolidWorks macro be unlocked?
For macros you own and are authorized to access, project protection can generally be removed or reset as part of recovery. We do not work on files you cannot legitimately claim.
How should I back up my SolidWorks macros?
Keep copies of the .swp files themselves, and additionally export the modules, forms, and class modules from the VBA editor as text files. The text exports make partial or total recovery trivial even if the container is later damaged.
If a macro that matters to your workflow has stopped loading, send it to us for a free evaluation. We will examine the file, tell you exactly what is recoverable, and quote the repair before any work begins.
Send us your .swp file for a free evaluation
Our recovery engineers will tell you exactly what can be recovered — at no cost. There is no charge if we cannot recover your data.
Start a free evaluation