So, I have created some macros to provide quick and easy selection, positioning and updating of images within a group shape.
I decided to present this article with VBA code rather than my preferred C# so that a stencil could be downloaded to provide instant usability, rather than having to install an add-in. It can be download from Image Utils.vssm, and should then be placed in to My Shapes folder, so that it becomes available to open in Visio. When it is opened, then the macros will need to be enabled.
There are just five public macros:
- Img_Utils.modImgs.AnchorImageInGroup – Set anchor option of an image shape within a group shape
- Img_Utils.modImgs.LockImageInGroup – Set lock options of an image shape within a group shape
- Img_Utils.modImgs.SelectReplaceImageInGroup – Allows for manual selection of an image file to replace an existing image shape within a group shape
- Img_Utils.modImgs.SetImageFormulas – Set the ShapeSheet formulas of an image shape within a group shape
- Img_Utils.modImgs.SizeImageInGroup – Set resize options of an image shape within a group shape
The SelectReplaceImageInGroup macro uses a references to the Excel object library to provide the Application.FileDialog(..) method, which is not available in the Visio object library….
Also, the Microsoft Scripting Runtime is referenced, and the code is digitally signed.
Here is a 16 minute video of the code in action, and an explanation of how it works! (Yes there is sound…).
Here are the sample Visio documents from the videos above:
Flags of the World.vsdx
Replacing Person Photos By Data.vsdx
Each of these documents require the Image Utils.vssm stencil to be open in the Visio UI, and Visio Professional or Visio Online Plan 2 is required for the Link to Data functionality, however the macros will work in Visio Standard too.
These are the CIA’s World Factbook links:
For those of you who have not yet updated to the latest Visio file format, here is the stencil in the old binary format: Image Utils.vss
Gustavo Garcia Lory (@garcialory) says
Great work David! It opens to Visio developers like me a new world of possibilities to manage photos in Visio based systems. Thumbs up!