PDA

View Full Version : Conditional Image Display



ligerdub
07-02-2012, 04:32 AM
Hi there,

I'm looking to generate a code (or other solution) that will display an image based on a conditional event.

In my case I have 7 different scenarios (it is a Word document which is taking information from an Excel file), which I hope to display a specific image based on whichever scenario materialises.

Is there an easy way for me to get this done?

Many thanks.

macropod
07-02-2012, 04:52 AM
How are the Excel data finding their way to the Word document (eg mailmerge, vba)? Is the image to already be in the Word file, or is it to be on disk? If the latter, is the image name and path is the Excel data? If not, where are the images located?

ligerdub
07-02-2012, 05:09 AM
Hi Paul,

Most of the word doc information sourced from the Excel file is linked to the original cell values in the Excel file. This has mostly been text entries and data used to generate charts. This has been fairly straight forward, but I'm stumped as to how to go about transferring the images used in the Excel workbook (themselves on display due to conditional formatting) to the Word document.

I have each individual image saved on a network drive if that is the easiest way to do it. I also have them stored within in the Excel workbook I have been basing my output on.

macropod
07-02-2012, 07:36 PM
In Excel, you'd need to have a cell somewhere that contains the values that triggers which of the conditional images gets displayed. In Word, you could then use field coding to test that cell's value and, on the basis of that test, display the relevant image from the file on held on disk. The field coding for this isn't exactly straightforward, though.

Assuming your images are named 'Image1.jpg' through 'Image7.jpg' and you have your reference cell established in Excel, copy & paste that into Word, using Paste Special with the 'paste link' option and the 'unformatted text' format. In Word, you'll see a value like, say, '1'. Select the '1' and press Ctrl-F9 to create a pair of field braces. You should see '{ 1 }'.

Next, use Windows explorer to navigate to the folder holding your images, then copy the folder path from Windows Explorer and paste it into the field, just after the left field brace. You should now see something like:
{C:\Users\ligerdub\Documents\Images 1 }

Now, edit the field code by:
• prefixing it with 'INCLUDEPICTURE "'
• adding an extra backslash for each of the path separators
• adding '\\Image' between the filepath and the '1'
• adding '.jpg" after the '1'
You should end up with something like:
{INCLUDEPICTURE "C:\\Users\\ligerdub\\Documents\\Images\\Image1.jpg"}

Press F9 to update the field and the linked image should display. If you now change the reference # in Excel, the image in Word should update.

If the images aren't sequentially numbered, the linking process can still be done, but the field coding gets a lot more complicated.

ligerdub
07-03-2012, 12:30 AM
Thanks very much for the detailed reply Paul.

Very helpful.