VBA Import/Export Addin

This free Visio add-in helps to import and export VBA code from Visio to a folder.
The addin can exports and import the code from "ThisDocument", forms (.frm), classes (.cls) and modules (.bas)

It may be handy if you want to track changes to the VBA code which is located in a template or a stencil. For example, you can compare it with previous versions, or put the exported folder under a source control, like GIT or TFS. So that you always know what was changed in comparison with the previous version.

06-03-2016 0-43-21

Download

FileDescriptionSizeDate
VisioImportExportVba.msi VBA Import/Export Addin (offline)912.0 KiB10.05.2017
VisioImportExportVba-1.0.3.msi Updated command line tool: now the files are saved automatically.912.0 KiB27.08.2017
setup.exe VBA Import/Export Addin (online)414.9 KiB10.05.2017

The "online" version is a VSTO-based click once installer, with built-in auto-update. The "offline" installer is a self-sufficient, no connection to the internet required for the target machine (can be installed both per-user and per-computer). Note that for "offline" version in case if you are still using Visio 2007 you may need to install VSTO runtime and SP3

Functions

If you click "Export VBA", the addin prompts you to select export folder, and writes VBA project content of the current document to that folder. The file names correspond to the VBA project items, such as forms/classes/modules. This document content is saved as "ThisDocument.bas". The next time you click "Export VBA" the project will be re-exported to the same folder (the addin remembers last export folder). To specify another, you can click drop-down arrow and select it.

If you click "Import VBA", the addin will prompt you to select folder with files on the disk. All files from this folder will be imported into the project, overriding what’s currently there. You can select for example the folder you exported your files to when using "Export VBA"

The option to "Include Sntecils" allows you to import/Export also code from the drawing’s stencil (can be selected only for templates and drawings). Means, the addin can also export/import code from the attached stencils (these are saved in sub-folders that correspond to the stencil names)

The option to "Clear Before Import" will remove all the content of the VBA project before importing (means, every vba component will be removed from the file), and then the content of the folder will be imported. Make sure you use that with care.

Requirements: Visio 2007 SP3 or above, NET 4 or above.

For the tool to work make sure you enable programmatic access to VBA project (in Visio security options). Otherwise you’ll get message that it’s disabled.

07-03-2016 22-56-14

Command-line (CLI) interface

The extension comes with command line interface, usable from powershell or batch file scripts. Means, you can do batch processing of Visio files using it as well. Please note that command line executable is added to current PATH automatically only in case you install offline version, i.e. VisioImportExportVba.msi (912.0 KiB)

This function could be useful, if (for example) have a bunch of files, and want to examine or replace VBA code in all of them.

Some examples:

To extract all code from a single Visio file to the current folder:

vba_import_export.exe export C:\MyVsiioFiles\MyFile.vsd

To extract all code from a single Visio file to a specified folder:

vba_import_export.exe export C:\MyVsiioFiles\MyFile.vsd -o C:\TragetFolder

To process all files in directory, and export VBA code from each of them to some other directory, creating a directory-per-file (using powershell)

foreach ($file in Get-ChildItem "C:\MyVisioDocuments\*.vsd")
{
  &vba_import_export.exe export $file.FullName -o C:\MyVisioDocuments\$($file.Name).exported
}

To replace VBA code in every file in folder C:\MyVisioDocuments\ with the code from folder C:\MyVisioDocuments\MyCode, and delete all existing code (using powershell):

foreach ($file in Get-ChildItem "C:\MyVisioDocuments\*.vsd")
{
  &vba_import_export.exe import $file.FullName -i C:\MyVisioDocuments\MyCode -c
}

All addin functions are available via the command line. The basic actions (verbs) are:

export – Export the VBA to the specified folder
import – Import VBA code from the specified folder.
help – Display more information on a specific command.

Each action supports number of sub-options, such as input/output path, etc.
For example, for export you can find out the options using "help" command:

help export:

PS>vba_import_export help export

USAGE:
Export to current directory:
 vba_import_export export file1.vsd
Export to other directory:
 vba_import_export export file1.vsd -o c:\dir\other

 -o, --output-directory Target directory to export VBA modules. If it does
                        not exist, it will be created. Current directory by
                        default.
 -s, --include-stencils Include docked stencils in export.

 value pos. 0           Required. Visio file to process (source file).

help import:

PS> vba_import_export help import

USAGE:
Import from some directory:
 vba_import_export import file1.vsd -i c:\dir\other

 -i, --input-directory  Input directory that contains VBA modules to  import. 
                        Current directory by default.

 -s, --include-stencils Import also code into docked stencils.

 -c, --clear            Before importing new VBA code, remove all existing
                        VBA code.

value pos. 0 Required.  List of Visio files to process, VBA code
                        will be added to each of these files.

The addin is open-source:

https://github.com/nbelyh/VisioImportExportVba

Feel free to fire bugs there… 🙂