【发布时间】:2020-07-08 04:45:26
【问题描述】:
我有一个 VBA 脚本,它将获取图片并将它们粘贴到 Excel 中的特定单元格中,具体取决于另一个单元格的值。
Public Function PictureLookup(Value As String, Location As Range, Index As Integer)
Application.Volatile
Dim lookupPicture As Shape
Dim sheetName As String
Dim picTop As Double
Dim picLeft As Double
sheetName = Location.Parent.Name
'Delete current picture with the same Index if exists
For Each lookupPicture In Sheets(sheetName).Shapes
If lookupPicture.Name = "PictureLookup" & Index Then
lookupPicture.Delete
End If
Next lookupPicture
'Get position of cell calling the UDF
picTop = Location.Top
picLeft = Location.Left
'Add the picture in the right location
Set lookupPicture = Sheets(sheetName).Shapes.AddPicture _
("G:\My Drive\MY FOLDER\LOGOS\" & Value & ".jpg", msoFalse, msoTrue, picLeft, picTop, -1, -1)
'change the picture name
lookupPicture.Name = "PictureLookup" & Index
PictureLookup = ""
End Function
目前,图片以其原始大小插入 Excel。我希望它们都具有 0.38x0.38 的确切尺寸。我似乎无法弄清楚要在脚本中更改哪些属性才能发生这种情况。
谢谢
【问题讨论】: