LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _ Set myPic = ws.Shapes.AddPicture(Filename:=imageFileName, _ ' second but slower method (in Office 2016) With ws.Pictures.Insert(Filename:=imageFileName, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue)
' first and faster method (in Office 2016) So I guess, the older Shapes.AddPicture Method should work on all versions. I did not find the Pictures.Insert Method in the Microsoft Documentations and feared some compatibility issues. LockAspectRatio = msoTrue 'Put this later so that changing height doesn't change width and vice-versa) Set Shp = wsDestination.Shapes('myPicture') 'Strongly recommend using a FileSystemObject.FileExists method to check if the path is good before executing the previous command Sub Insert_Pic_From_File(PicPath as string, wsDestination as worksheet) The Shape Object will have that same name as the Picture Object. Insert your Pic assigned to a variable to easily change its name. To place a new image at a specific place, I recommend creating an image at the 'right' place and registering its top and left properties values of the dummy onto double variables.
If it's simply about inserting and resizing a picture, try the code below.įor the specific question you asked, the property TopLeftCell returns the range object related to the cell where the top left corner is parked.