根据 MS Excel 中的单元格值显示文件夹中的图像

s.k*_*aul 5 excel image

我想根据 Microsoft Excel 中的相关单元格值显示图像。

例如,

A1 = "mypic.png"        B1 cell should show mypic.png 
A2 = "anotherpic.png"   B2 cell should show anotherpic.png
Run Code Online (Sandbox Code Playgroud)

图片在同一个目录下。

有什么办法吗?

Kᴀτ*_*ᴀτᴢ 2

使用此代码,您可以在单元格中插入图像F20,其路径存储在单元格中A1。使用完整路径,例如D:\one.jpg. 更改Tabelle1您的工作表名称。

Sub Test()
    Dim objPicture As Picture
    With Tabelle1.Cells(20, 6) ' Picture starts in cell F20 -> change as you need 
        Set objPicture = .Parent.Pictures.Insert(Tabelle1.Cells(1, 1).Value)
        objPicture.Top = .Top
        objPicture.Left = .Left
        objPicture.Height = 150
        objPicture.Width = 150
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)