下午好
我发现下面的VBA代码可帮助我根据B列中的图像名称列表将图像从文件夹导入到A列中。效果很好,但它们只是引用,因此共享文件时不显示图像与另一个用户。对于vba来说是全新的,所以如果这是一个愚蠢的问题,请提前道歉。需要对此代码进行哪些修改,以便将图像嵌入文件中,而不仅仅是将其设置为链接?
不如图像嵌入重要,但是很想知道是否有一种方法可以将图像调整为单元格的最大高度或最大宽度(混合了风景/人像)。
非常感谢您的帮助!
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:\Users\Lalo Casanova\Desktop\MAIN 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
Next
End Sub