0
votes

I'm using Excel 2016 with Windows 10 and I insert a picture in cell B17 and then want to resize it while keeping the top left corner of the picture in the top left corner of cell B17. Some pictures resize to the bottom left corner while others resize to the top right corner. I tried using msoScaleFromTopLeft but I still get the same pictures shrunk down to the bottom left or top right.

Here's my macro VBA code:

Range("B17").Select

ActiveSheet.Pictures.Insert(PhotoLocation).Select  'Insert photograph from file.

Selection.ShapeRange.ScaleWidth 0.2, msoFalse, msoScaleFromTopLeft

What am I missing? Can someone please help me with this or suggest an alternative method to do what I want?

1
Take a look at the following link... the answer places the image relative to a range stackoverflow.com/questions/22073463/…Wayne G. Dunn
@wayne Please see comments below. Thanks for your help!Wenger1988

1 Answers

0
votes

You could try something different, you could Set an object to the picture you insert (without using Select and Selection).

Afterwards, you can modify it's properties using With myPic, and nested properties below.

Code

Sub SetPics()

Dim myPic As Picture
Dim PhotoLocation As String
Dim Rng As Range

Set Rng = Range("B17")

Set myPic = ActiveSheet.Pictures.Insert(PhotoLocation)
With myPic
    .ShapeRange.ScaleWidth 0.2, msoFalse, msoScaleFromTopLeft
    .Top = Rows(Rng.Row).Top
    .Left = Columns(Rng.Column).Left
End With

End Sub