Replacing Images in #Visio Shapes by Changing 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.

personphotosbydata

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…).

Alternatively, you can watch it on YouTube.

Here are the sample Visio documents from the videos above:

Flags of the World.vsdx

Replacing Person Photoes 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

Advertisements

2 Responses to “Replacing Images in #Visio Shapes by Changing Data”

  1. 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!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

JackBinnall

O365 and SharePoint

Simplify Tasks

Want to learn the simple way?

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

John Goldsmith's visLog

be smart, be clear, be visual ...

Mo's blog

Personal views on Dynamics 365 for Operations and Technical Architecture.

Chris Webb's BI Blog

Microsoft Power BI, Analysis Services, MDX, DAX, M, Power Pivot and Power Query

davecra.wordpress.com/

Azure Solutions for Office 365, and more...

johnvisiomvp

Life with Visio and other Microsoft Toys!

Nilsandrey's Weblog

Just another WordPress.com weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Smart graphics for visual people

%d bloggers like this: