PDA

View Full Version : Import Picture With Same Dimensions As Picture Already On Sheet



juan4412
07-11-2015, 11:38 AM
I am adding an image to Excel, one image is original picture, one is updated picture, I want the original picture to stay in the exact same location, but I want the updated picture to be same heightxwidth and be offset by 4 cells. This is my syntax, but the updated picutre is keeping its height & width not updating to mirror what the original picture has?

Set image = .Pictures.Insert("C:\" & employeename & "\" & employeename & ".jpg")
For Each Shape In ActiveSheet.Shapes
If (Shape.Name = "Old Picture") Then
Shape.Select
image.Left = Shape.Left + 30
image.Top = Shape.Top + 30
image.Width = Shape.Width
image.Height = Shape.Height
End If
Next

jolivanes
07-12-2015, 11:49 AM
Would this work?




Dim a As Long, b As Long
With ActiveSheet.Shapes("Original Picture") '<---- Change name as required
a = .Height
b = .Width
End With


' Code to import and place your new picture


With ActiveSheet.Shapes("New Picture") '<---- Change name as required
.LockAspectRatio = msoFalse
.Height = a
.Width = b
End With

snb
07-12-2015, 12:23 PM
or

Sub M_snb()
With Shapes("first")
Shapes.AddPicture "G:\OF\werkblad.gif", 1, -1, .TopLeftCell.Offset(, 4).Left, .Top, .Width, .Height
End With
End Sub