Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing an Object's Picture (& hidden objects)

Status
Not open for further replies.

tmktech

MIS
Oct 3, 2002
78
US
Hello folks.

I've got an EXCEL VBA app where I need to dynamically change a object's picture based on a variable. I've got an image folder and can easily assign AND change the image using the following code (using a Label in this case):

ActiveSheet.Label1.Picture = _
LoadPicture("C:\_Imagefolder\xyz.jpg")

MY CONCERN IS THAT THE .PICTURE is a hidden object replaced by SHAPES (and I assume no longer to be supported sometime in the not-too-distant future). I want to make sure this code functions for the long haul (or until MS comes up with another new approach). So I tried to find the solution using the shapes object. And this is what I've got:

myFileName = "C:\_Imagefolder\xyz.jpg"
With TargetRange
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With

Set myshape = ActiveSheet.Shapes.AddPicture _
(Filename:=myFileName, LinkToFile:=True, _
SaveWithDocument:=False, Left:=l, Top:=t, _
Width:=w, Height:=h)

But how do I CHANGE the picture in place??? Another .addpicture just overlays another image.

ALSO, for either coding solution, I want to "size to fit" the image without distorting the original proportions. Setting the "relative to original picture size" switch doesn't appear to help.

Any help would be greatly appreciated.

Waiting to give a star....
TMKTECH
 
I found the .userpicture to be an easy way to FILL the background of the shape (AND CHANGE IT) as follows:

ActiveSheet.Shapes("Rectangle 309").UserPicture _
Picturefile:="C:\_Imagefolder\xyz.jpg"

NOW, I just need to maintain the pictures proportions versus being stretched. I see .PICTUREFORMAT as a paramter (with xlscale, xlstrech, etc.) but can't get the syntax to work.

HELP!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top