After change from Picture.Insert to Shape.AddPicture picture image is shifted

motif

New Member
Joined
Dec 15, 2019
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
Hi,
Hi I had to modify excel template VBA code to make image logo persistent outside the network
so I change simple Picture.Insert(pfile) to:

Set vOldShape = vSheet.Shapes(pName)

If Not vOldShape Is Nothing Then
vLeft = vOldShape.Left
vTop = vOldShape.Top
vWidth = vOldShape.Width
vHeight = vOldShape.Height

'Set vNewShape = vSheet.Pictures.Insert(pFile) -> old code

'changes:
Set vShape = vSheet.Shapes.AddPicture(Filename:=pfile, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoCTrue, _
Left:=vLeft, _
Top:=vTop, _
Width:=-1, _
Height:=-1)

With the commented out old code image is place correctly, but with the AddPicture is shifted to the left, why could it be?
I tried also to lock aspect ratio or not usuing -1 just properties of old image but not luck, anybody can help?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
also is it possible to embed image with Pictures.Insert so it be saved with document?
I need only that one functionality. thanks
 
Upvote 0
Actually I know what is happening but not sure why, macro is using template with predefined shape.
When columns are inserted, AddPicture image don't move with shape but stays.
Not the case with Insert.Image which is moving with columns, any idea why?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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