0

我有一些具有某些值的单元格。该值是文件夹中图片的名称。当我单击单元格“值”时,我想显示名为“值”的正确图片。我想动态地执行此操作,以便在单击具有名称值的单元格时添加图片会导致显示它。你能告诉我应该从哪里开始吗?是否有任何教程显示如何执行此操作?我发现了很多,但他们使用列表并将图片存储在 Excel 工作表中。有没有例子?

4

1 回答 1

0
Private Sub CommandButton2_Click()
           On Error Resume Next
          Dim imageFolder As String 'this is the folder where the image is located
    Dim imagePath As String


    Cells.Find("Code").Offset(1).Select
Range(Selection, Selection.End(xlDown)).Select
For Each cell In Selection
imageFolder = cell.Value
imagePath = "C:\Documents and Settings\kollol\My Documents\Quotes\Image\" & imageFolder

cell.Offset(0, 2).Select

ActiveSheet.Pictures.Insert(imagePath & "\" & "1.jpeg").Select ' here the name of the image is 1.jpg


 With Selection
.Placement = xlMoveAndSize
 .ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Width = ActiveCell.ColumnWidth
 .ShapeRange.Height = ActiveCell.RowHeight - 5
.ShapeRange.IncrementLeft 10.5
.ShapeRange.IncrementTop 4#
 End With

Next cell

End Sub
于 2014-06-07T14:06:18.410 回答