How to Automate Batch Importing SVG Icons into a Microsoft Visio Stencil
Question details
The user needs to batch-import hundreds of SVG vector icons into a Microsoft Visio stencil automatically instead of doing it manually.

- Product
- Microsoft Visio
- Device & OS
- not provided
- Scenario
- Building a comprehensive, custom Microsoft Visio stencil library using a large folder of downloaded or designed SVG files.
- Observed behavior
- Microsoft Visio lacks a native batch-import feature for SVG files, requiring users to rely on a programmatic workaround to automate the process.
Gather all your SVG icons into a single local folder and ensure the Developer tab is enabled in Microsoft Visio so you can access the Visual Basic editor.
Use a VBA Script to Automate SVG Imports
Create and run a VBA macro that iterates through a designated folder, imports each SVG file, scales it, and adds it as a master shape in a new stencil.
Because Visio does not offer built-in batch processing for SVG files, you can utilize the Visio Object Model via Visual Basic for Applications (VBA). By writing a script that loops through your file directory, you can automate the repetitive task of inserting, grouping, and saving each icon.
Launch Microsoft Visio, go to the Developer tab, and click on 'Visual Basic' to open the VBA Editor environment.
Right-click on your Visio document project in the Project Explorer, select 'Insert', and choose 'Module' to open a blank scripting window.
Write a script utilizing the `FileSystemObject` (or the `Dir` function) to loop through your SVG folder. Use the `ActivePage.Import` method within the loop to bring each SVG into a temporary drawing page.
In the same script, group the imported elements, adjust dimensions using shape properties like `Width` and `Height`, and use the `Document.Masters.Drop` method to save the finalized shape into your target stencil.
Before processing hundreds of files, copy 5 to 10 SVG files into a separate test folder. Run your macro against this test folder to ensure scaling, alignment, and stencil generation work exactly as intended.

Try WPS Office for Lightweight Document and Diagram Creation
While advanced tasks like batch-importing SVGs into Visio stencils require complex VBA coding, WPS Office offers a free, lightweight suite with user-friendly built-in tools for documents, spreadsheets, presentations, and flowcharting. It provides high compatibility with Microsoft Office formats, allowing you to manage design assets and professional reports without steep learning curves.
- 1. Download and Install WPS Office: Visit the official WPS website, download the installer, and complete the quick installation process.
- 2. Open a Presentation or Document: Launch WPS Office and start a new blank Presentation or Writer document to begin building your visual reports or simple diagrams.
- 3. Insert Vector Assets: Navigate to 'Insert' > 'Picture' to easily browse your computer and drop SVG or PNG assets directly into your workspace.

Frequently Asked Questions
Can I batch import SVG files into a Visio stencil without using code?
No, Microsoft Visio does not currently include a native user interface feature to select multiple SVG files and batch convert them into a stencil. You must either import them individually or rely on automation via VBA or C#.
Why do my SVG files look distorted after importing them into Visio?
SVG files may appear distorted if their internal viewBox settings conflict with Visio's rendering engine. When building your automation script, ensure you group the imported elements and explicitly define the shape's Width and Height properties to lock the aspect ratio.
Can I use C# instead of VBA to automate Microsoft Visio?
Yes. You can create a Visio Add-in using C# via Visual Studio Tools for Office (VSTO). The complete Visio Object Model is accessible through C#, allowing you to loop through directories, import files, and manipulate stencils similarly to VBA.
How do I safely test my VBA script before running it on hundreds of icons?
Always create a separate test folder containing a small selection (e.g., 5 to 10) of your SVG icons. Point your VBA script's directory path to this test folder first. This allows you to verify that the shapes are scaled correctly and the stencil saves properly without risking crashes or freezing Visio.




