Programatically control picture property of Image control
Fixes:
There is no "Controls" collection in the Excel application, or even for a
workbook or worksheet, so you can't use your For Each loop this way. If the
Images on you sheets are from the Controls toolbox they are actually Shape
objects with a Shape.Type of 12. So you need to iterate through the Shapes
and then check the shape type to see if it is an image or not.
I think this will work:
Sub GetPics()
Dim XLShape as Shape
For each XLShape in Sheets("ImageSheet").Shapes
If XLShape.Type = 12 Then
XLShape.DrawingObject.Object.Picture = LoadPicture _
Application.WorksheetFunction.VLookup(c.Name,Range ("DataTable"),3,False))
End If
Next XLShape
End Sub
"Brassman" wrote:
I have a workbook with a table similar to this:
Item No. | Description | PicPath
ITEM1 | Item 1 description | C:/Images/a pic.jpg
ITEM2 | Item 2 description | C:/Images/another pic.jpg
On other sheets, I have vlookup functions calling records from the table. I
also have image controls on those sheets, named the Item No.s (ITEM1, ITEM2).
Is there a way I can programatically loop through those images and set the
picture property? This is the basic idea of what I want to do, but it doesn't
work. How do I need to fix it? Thank you very much.
Code:
Sub GetPics()
Dim c as Image
For each c in Controls
c.Picture = LoadPicture(Application.WorksheetFunction.VLookup( c.Name,Range
_("DataTable"),3,False))
Next c
End Sub
|