Dynamic Picture Viewer

Saighead

New Member
Joined
May 17, 2013
Messages
34
Hi,

I have a list of image file names (minus the extensions) in column A and an Image ActiveX control embedded on Sheet1. Could you help me with a code that would access and display the images? For instance, when a cell in column A containing "Image1" is selected, Excel should access "c:\images\Image1.gif" and display it in the Image ActiveX control.

All images are gif files and all are stored in c:\images\.

_________
Question also posted here
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
This will only work for GIF files if you put a file with a different extension you will get a message box telling you that the file does not exist

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A2:A7")) Is Nothing Then
    Dim mpath As String
    Dim haserror As Boolean
    mpath = "C:\images\" & Target & ".gif"
    haserror = True
    On Error GoTo error
    Sheets("Sheet1").Image1.Picture = LoadPicture(mpath)
    Image1.PictureSizeMode = 3 'Change to 0, 1, 3 depending on what you want.
    haserror = False
End If
If haserror Then
error:
    MsgBox "file does not exist"
End If
End Sub

for more info on the picturesizemode see here
https://docs.microsoft.com/en-us/of.../user-interface-help/picturesizemode-property
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top