A newsgroup poster asked a question this week about how he could link images within his Org Chart data.
Under normal conditions the Org Chart addon enables you to add images on a one-by-one basis. The Insert Picture... context menu option produces a file picker dialog that waits for the user to select an image file before continuing its process and this gets in the way of any proper programatic access...
My proposed solution is to use a little code to simulate the addon's Insert Picture function, but I'm intentionally not going to go into too much detail about how this works in this post so that I don't scare off the non-coders amongst you. If you are in this group then don't worry - if you know how to Copy and Paste then you should be able to work through following example fairly easily. If you're in the coding group though, I used the SDK's Event Monitor tool to understand what the Org Chart is up to and I'll elaborate on this in the next post.
The basic process is as follows:
- add a column of image file names to your Org Chart spreadsheet data
- create your Org Chart
- run some code to review all your shapes and where it finds an image file path, add the actual image to the respective shape
Using the linked image code - A walkthrough
- in Excel, start by adding a column to your existing Org Chart spreadsheet named 'ImageFile'
- add an associated image file name to each row
- in Visio select File / New / Business / Organization Chart Wizard
- run through the wizard and when you get to the Shape Data step, ensure you add the ImageFile item to the right hand column
- as you complete the wizard, a new Org Chart should be created
- save the file to a specific folder and ensure that your image files (that you specified in your spreadsheet) are also in the same folder
- now for the Copy and Pasting part - Download the zip file at the bottom of this post, open the OrgImageCode.txt file within it and copy the text (press Ctrl+A to select all of the text and the Ctrl+C to copy it)
- back in Visio, press Alt+F11 to launch the VBA editor (VBE)
- on the left hand side, in the Project Explorer, double click the ThisDocument item, which should open a blank code pane on the right
- click in the right hand code pane and press Ctrl+V to paste your code and then close the VBE.
- with your Org Chart showing in the drawing window select Tools / Macro / ThisDocument / RefreshOrgChartImages
- the images should be added to each shape that contains a file reference. If this doesn't work check that your file matches the sample in the zip file below or drop me a line in the comments below.
If you want to use full file paths in your data (and so open the possibility of diffent file locations) then you just need to edit a couple of lines in the code - Have a look at the Get the file name for the associated image section in the AddImage function.
Anyway, I hope I've been clear enough for the non-coders out there and if not then please do add a comment below.
You can download a zipped file set of an example Visio doc, the Excel data and associated images here: Download LinkingOrgChartImagesSample.zip