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'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