EXCEL - IMAGE ACTIVE CELL

Copper Contributor

Hi, there a way to pull images from another worksheet?

I use this code, but only active by a folder.

He create a shape Image beside the active cell.

Lets say you have to send to someone, but the person will not see because he do not have the folder with the images. Please help

 

***

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'FOTO AO SELECIONAR CELULA'

On Error Resume Next

If Target.Row > 1 And Target.Value <> "" Then
Me.Shapes.Range(Array("FOTO")).Delete

Dim FullImagePath As String

FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".jpg"
If Dir(FullImagePath) = "" Then
FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".jpeg"
If Dir(FullImagePath) = "" Then
FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".png"
If Dir(FullImagePath) = "" Then Exit Sub
End If
End If

Me.Pictures.Insert(FullImagePath).Select
With Selection
.Name = "foto"
.Left = 400
.Height = 100
.ShapeRange.Shadow.Type = msoShadow21 'Adciona sombra
End With

Target.Activate
Else
Me.Shapes.Range(Array("FOTO")).Delete
End If

End Sub

 

 

EXEMPLE WHAT I WANT TO DO:

ezgif-3-40a9193477.gif

11 Replies

@WLLIAN 

If you want to embed the images directly into the Excel workbook rather than relying on external image files, you can maybe use the following modified VBA code. This code embeds the images into the worksheet and displays them in a shape (image) next to the active cell:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'FOTO AO SELECIONAR CELULA'

    On Error Resume Next

    ' Delete the existing image shape
    Me.Shapes.Range(Array("FOTO")).Delete

    If Target.Row > 1 And Target.Value <> "" Then
        Dim FullImagePath As String
        Dim imgShape As Shape

        ' Get the full path to the image file
        FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".jpg"
        If Dir(FullImagePath) = "" Then
            FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".jpeg"
            If Dir(FullImagePath) = "" Then
                FullImagePath = ThisWorkbook.Path & "\FOTO\" & Target.Value & ".png"
                If Dir(FullImagePath) = "" Then Exit Sub
            End If
        End If

        ' Insert the image into the worksheet
        Set imgShape = Me.Shapes.AddPicture(FullImagePath, _
                          MsoTriState.msoFalse, MsoTriState.msoCTrue, _
                          Target.Left + Target.Width, Target.Top, 100, 100)

        ' Customize the image shape
        With imgShape
            .Name = "FOTO"
            .Shadow.Type = msoShadow21 ' Add shadow
        End With

        Target.Activate
    End If
End Sub

This code uses the Shapes.AddPicture method to insert the image directly into the worksheet. The image is placed next to the active cell, and you can customize the size and position according to your requirements.

Remember that embedding images directly into the workbook can increase its file size. If file size is a concern, consider keeping the images in a separate folder or using a different solution based on your specific needs. The text was created with the help of AI.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

 

Was the answer useful? Mark as best response and like it!

This will help all forum participants.

@NikolinoDE 

 

Failed. kkk

It work with the folder the code you send to me :), but is not the way i wish.

Thank you for the advice of the file size, but is just some images.

I have that project on my pc, its beautiful.

But i wish to send to someone and that person open the file and see the file just like me.

I made a lot of research and i could not find anything like that.

Most videos on youtube or sites only teach with Folders, never on the Worksheet.

I could you vlookup, but is not dynamic.

I could use function Image, but is not dynamic.

I Could use an Object, but is not dynamic.

 

After you see the video, you will agree with me

 

 

https://www.youtube.com/watch?v=7OJI2uTc2II&t=71s&pp=ygUWZXhjZWwgaW1hZ2VtIGFvIGNsaWNhcg%3D%3D

@WLLIAN 

If you're in a fully updated Excel 365, there's no need to use code because the version supports 'place in cell' for pictures.

 

It's easy to set up. Even if you have a folder with multiple images.  When you insert the pictures Excel will place them vertically in the column, 1 picture in 1 cell as far as needed.

 

You could start by setting up a sheet with the pictures like this:

Patrick2788_0-1703713460788.png

 

Next, you setup a sheet with the input cells as such (Your arrangement may be different, but you get the idea):

Patrick2788_1-1703713551749.png

 

This gif shows what it looks like in motion:

Place in cell.gif

demo 

save images online?



@Patrick2788 

No my friend. This is not what i want. But thank you.

If you see the video, the Image is a Shape that pops up when target a cell, erase the shape when change to another target name and erase when the cell is blank.

The Shape always stay beside the cursor

I dont want vlookup or Function Image kkkk.

Thank you for your time my dear friend.

Exemplo what i want to do:

ezgif-3-3fd9551ab3.gif

The images it will be in another worksheet.
Sorry your file is japonese. I dont understand kkk

@WLLIAN 

It seems you are looking for a solution to dynamically display images in a shape based on the active cell's value, and you want the images to be stored in another worksheet. Unfortunately, Excel does not have a built-in feature to dynamically display images (so far I know) in this way without relying on external files or folders.

However, you can create a workaround using Excel's Picture function and named ranges. Here's a general approach:

  1. Create a Named Range for Each Image:
    • In the worksheet where the images are stored, create a named range for each image. You can do this by selecting the cell with the image, going to the "Formulas" tab, and choosing "Define Name."
  2. Modify the VBA Code:
    • Adjust the VBA code to use the Picture function and reference the named ranges dynamically. Replace the existing VBA code with the following:

Vba code (is untested):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next

    ' Delete the existing image shape
    Me.Shapes.Range(Array("FOTO")).Delete

    If Target.Row > 1 And Target.Value <> "" Then
        Dim imgName As String
        Dim imgShape As Shape

        ' Get the name of the image range based on the target value
        imgName = "Image_" & Target.Value

        ' Insert the image into the worksheet
        Set imgShape = Me.Pictures.Insert(ThisWorkbook.Names(imgName).RefersToRange.ImageBytes)

        ' Customize the image shape
        With imgShape
            .Name = "FOTO"
            .Left = Target.Left + Target.Width
            .Top = Target.Top
            .ShapeRange.LockAspectRatio = MsoTriState.msoCTrue
            .ShapeRange.Width = 100
            .ShapeRange.Height = 100
            .Shadow.Type = msoShadow21 ' Add shadow
        End With
    End If
End Sub

 

3. Create Named Ranges for Images:

    • Ensure that each image in the image worksheet has a unique name (e.g., Image_Apple, Image_Orange).

With this approach, each image is treated as a named range, and the VBA code dynamically inserts the image based on the active cell's value.

Please note that this is a simplified solution, and you may need to adapt it based on your specific requirements and the structure of your workbook. Additionally, ensure that the image names in the image worksheet match the expected names in the VBA code.

 

If this doesn't help you, please provide more detailed information. Excel version, operating system (Mac, Win., Server, etc.), storage medium (Sharepoint, OneDrive, etc.), file extension (xlsx, xlsm, etc.). They wrote this, The images it will be in another worksheet. Do you mean worksheet or workbook? More detailed information will help to suggest a more precise solution.

@NikolinoDEHi. I try, but i must doing a lot of things wrong. kkkk

I share in One drive, link below if helps :)

 

https://onedrive.live.com/edit?id=36169DA5A4F12415!152127&resid=36169DA5A4F12415!152127&ithint=file%...

 

Windows 10 = 64

Microsoft 365

.xlsm

 

screen-recorder-thu-dec-28-2023-08-19-49.gif

@WLLIAN 

Why use a shape when the image can be placed in cell? Looks like a difference in philosophy. I try to avoid using code if at all possible. It introduces a security element and things can get messy if others need to access the workbook.

@Patrick2788Hi. Put a image into a cell make the row change the size.
I like this way, i think is dynamic. Cool. Something different, impress... you see.

Let say you have to send a file to your boss and 10 person send that medium file, basic... and you send a new way of see that file or even to others see.

Most people dont know what excel is able to do.

I love excel and yes i have another files that i use image with vlookup or Objet with image, very simples but i love.

I just wish to make that projet, i love learn excel a little bit every day.

Its a taste thing, everyone like their own way to make spreadsheets kkkk