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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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