positioning image by using VBA

mahsa

New Member
Joined
Jan 10, 2019
Messages
5
Hello everyone,
I am writing a VBA code in order to insert an image in a specific cell. everything works properly except the horizontal position; no matter what cell I define in the code, it always appear a bit to the left. can someone please tell me what's wrong? Thank you in advance!
here is the code:


Dim path As Variant
Dim pic As Variant
path = Application.GetOpenFilename
If path = False Then Exit Sub
Set pic = ActiveSheet.Pictures.Insert(path)
With pic.ShapeRange
'Resize Picture to fit in the range....
.Left = Range("k1").Left
.Top = Range("k1").Top
.Width = Range("k1:m1").Width
.Height = Range("k1:k3").Height
End With
pic.Placement = xlFreeFloating
pic.PrintObject = True
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi
Welcome to the board

Maybe the proportions of the dimensions of the image are not the same as the ones of the range?
Try turning .LockAspectRatio off.

This means, of course, that you'll lose the original proportions of the image.
 
Last edited:
Upvote 0
Hi,
Thank you very much but it didn't work. I think that it can be possible to be because of the image properties itself because when I choose another picture to insert, it goes a little to the left!
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top