This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
This VBA macro handles the creation of new document in SOLIDWORKS (part, assembly or drawing) using SOLIDWORKS API and allows to automatically run custom code or another macro when this event happens. This macro will also handle creation of new virtual document in SOLIDWORKS assembly.
Configuration
Create new macro (e.g. RunOnNewDocCreated.swp)
Copy the code into corresponding modules of the macro. The VBA macro tree should look similar to the image below:
Place your code into the main sub of the HandlerModule module. The pointer to IModelDoc2 document is passed as the parameter. Use this pointer instead of ISldWorks::ActiveDoc as new document might not be set to active when this event arrives.
Sub main(model As SldWorks.ModelDoc2)
'TODO: add your routine hereEndSub
Custom VBA code which needs to be run for each newly created document
Sub main(model As SldWorks.ModelDoc2)
'TODO:implement the procedure
MsgBox "File create: " & model.GetTitle()
EndSub
Notifications
Join session by SOLIDWORKS and PDM API expret Artem Taturevych at 3DEXPERIENCE World 2025 on Feb 26 at 08:30 AM CST to explore 10 essential macros for automating drawings, assemblies, custom properties, and more