Thread: linking photos
View Single Post
  #2   Report Post  
Ed Ferrero
 
Posts: n/a
Default

HI Smitty,

You can use the method described in my earlier reply to Joe William.

Assume that 'cow#1', 'cow#2' etc are in cell A1 of each sheet.
Assume cell A2 contains the path for each picture.

This code will create a blank chart on each sheet in a workbook, and
import a picture into the chart based on the contents of cell A1 and A2.

The pictures are not linked, so it is safe to send the resulting workbook
to a client.

The code has been modified slightly to make it more generic. You need
to run the macro 'SetPicsForAllSheets' once to set the pictures for
all worksheets.

Sub SetPicsForAllSheets()
Dim sh As Worksheet
Dim strPic As String
Dim strPth As String
Dim strExt As String

For Each sh In ActiveWorkbook.Worksheets
strPic = sh.Range("A1") ' name of picture to import e.g. cow#1
strPth = sh.Range("A2") ' path of picture e.g. C:\My Documents\
strExt = sh.Range("A3") ' file extension for picture e.g. .jpg, .gif

Call BuildChartPic(sh.Name, strPic, strPth, strExt)
Next sh
End Sub


Sub BuildChartPic(strSht As String, strPic As String, strPth As String,
strExt As String)
Dim ch As ChartObject
' build full path and file name
strPic = strPth & strPic & strExt

Set ch = Worksheets(strSht).ChartObjects.Add(100, 30, 400, 250)

ch.Activate
ActiveChart.ChartArea.Fill.UserPicture PictureFile:=strPic

End Sub

Ed Ferrero
http://edferrero.m6.net

Oddly enough I was going to just post a question about bringing in a new
picture depending on what doc I was in, and lo-n-behold, the answer may be
very similar to Joe Williams.

I'll make this very generic. :-) I have one multi-sheet Excel file with
a
picture on the top of each page. We'll say each report is about one cow.
This report will be duped with new numbers for 20 different cows. Now I
would like the picture of the cow on the top of each page to change
depending
on what cow we're reporting on. So if report #1 is about cow #1, I want
to
be able to tell the report to update each picture to that of cow #1.
After
it updates, it needs to break any links that it established (don't know if
it
would, but I can't send it to the client with it trying to update
anything).
Then I move on to report #2 about cow #2, and it updates to the picture of
cow #2.

Does that make sense? If not let me know and I'll try it again. Thanks
very much!!

Excel 2002