Show image from folder based on cell value in MS Excel

I want to show a base of images relative to the value of a linked cell in Microsoft Excel.

For example,

A1 = "mypic.png"        B1 cell should show mypic.png 
A2 = "anotherpic.png"   B2 cell should show anotherpic.png

      

The images are in the same directory.

Is there a way to do this?

+3


source to share


2 answers


With this code, you can insert an image into a cell F20

using the path that is stored in the cell A1

. Use the full path like D:\one.jpg

. Change Tabelle1

to your sheet name.



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

      

+2


source


I am still facing the problem. I have a folder named X and in it I have several folders named a, b, c and in that folder there are images. Now I want that after traversing one image path in A1, the image of that path appears in B1.

I tried to do the same using the VBA code above but ran into obj not found error.



Please, help

0


source







All Articles