(Solved) – How do you embed images into Excel with vba macro instead of referencing them? [duplicate]

  • by

This question already has an answer here:

Good afternoon,

I found the VBA code below that helps me import images into column A from a file folder based on a list of image names in column B. Works great, but they are only references, so images dont appear when the file is shared with another user. Totally new to vba so apologies in advance if this is a dumb question. What modifications need to be made to this code so the image is embedded into the file and not just set as links?

Not as important as image embedding, but would love to know if there is a way to make the images resize to the maximum height or width of the cell (there’s a mix of landscape/portrait images).

Thank you so much for your help!

Sub Picture()
Dim pictname As String
Dim pastehere As Range
Dim pasterow As Long
Dim x As Long
Dim lastrow As Long

lastrow = Worksheets("PPVendorPricing12.9").Range("B2").CurrentRegion.Rows.Count
x = 2
For x = 2 To lastrow
Set pastehere = Cells(x, 1)
pasterow = pastehere.Row
Cells(pasterow, 1).Select 'This is where picture will be inserted

pictname = Cells(x, 2) 'This is the picture name
ActiveSheet.Pictures.Insert("C:UsersLalo CasanovaDesktopMAIN PRODUCT IMAGES" & pictname & ".jpg").Select 'Path to where pictures are stored

With Selection

.Left = Cells(pasterow, 1).Left
.Top = Cells(pasterow, 1).Top

.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = 130#
.ShapeRange.Width = 130#
.ShapeRange.Rotation = 0#
End With


End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *