Forum Discussion
WLLIAN
Dec 27, 2023Brass Contributor
EXCEL - IMAGE ACTIVE CELL
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:
- WLLIANBrass Contributor
The images it will be in another worksheet.
Sorry your file is japonese. I dont understand kkk
- Patrick2788Silver Contributor
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:
Next, you setup a sheet with the input cells as such (Your arrangement may be different, but you get the idea):
This gif shows what it looks like in motion:
- WLLIANBrass Contributor
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:
- peiyezhuBronze Contributorhttps://m.toutiao.com/article/7317779366447153699/?tt_from=copy_link&utm_campaign=client_share&enter_from=click_creation_center&gd_ext_json=%7B%22enter_from%22%3A%22click_creation_center%22%2C%22category_name%22%3A%22creation_center%22%7D&utm_source=copy_link&utm_medium=toutiao_android&share_token=796f12f4-479e-4cf5-b656-6e2726c136f9&category_name=creation_center
video:
https://m.bilibili.com/video/BV1kt4y1f7XE?buvid=XX85E838539534AD650323D79CEE8DA100517&from_spmid=default-value&is_story_h5=false&mid=FSMZLyVVbtrPTKay0%2Fc9Fg%3D%3D&p=1&plat_id=116&share_from=ugc&share_medium=android&share_plat=android&share_session_id=a1cb7e42-b66d-4c68-83d6-dfacb0430ed7&share_source=COPY&share_tag=s_i&spmid=main.ugc-video-detail.0.0×tamp=1703803765&unique_k=gfHQpEU&up_id=634143044&share_times=1
- NikolinoDEGold Contributor
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.
- WLLIANBrass Contributor
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
- NikolinoDEGold Contributor
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:
- 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."
- 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.