Reputation: 1
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?
Upvotes: 0
Views: 1192
Reputation: 33682
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
Upvotes: 0