Site icon bVisual

Replacing Images in Visio Shapes by Changing Data

Replacing Images By Data

I wrote an article last year about Swapping Images in a #Visio Shape manually, but I want to be able to do this whenever a Shape Data value changes. This is because I use I invariably use shapes linked to data. I also want to be able to have multiple images within a single grouped shape, and all of them changing when their referenced Shape Data values change. I believe that this will be more adaptable for a lot of scenarios than trying to repurpose Data Graphic Icon Sets ( see  Make Your Own Visio Data Graphic Icons Sets … automatically). I also discovered that the Shape.ChangePicture(…) function can just as easily work with urls as it can with network file paths, so even more possibilities are opened up! For example, the Visio Online JavaScript API has the ability to overlay an image (see ShapeView.addOverlay(…)).
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:

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:
https://www.cia.gov/library/publications/resources/the-world-factbook/appendix/appendix-d.html
https://www.cia.gov/library/publications/the-world-factbook/attachments/flags/CM-flag.gif
https://www.cia.gov/library/publications/the-world-factbook/docs/flagsoftheworld.html
Note :
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

Exit mobile version