How to view graphic files from excel?

  • Thread starter Thread starter Kiknadze Lado
  • Start date Start date
K

Kiknadze Lado

Dear all,

Let I have excel sheet with two columns:

RefNo, Description

g1234 file1
g1235 file2
g1236 file3
................

First column cell values connected with graphic file names from the same
directory. This means that I have graphic files: g1234.jpg, g1235.jpg,
g1236.jpg ....in the same directory there is opened worksheet.
I want to write program which will operate by following way:
If I will click cell with the value g1234 then I want to view graphic file
g1234.jpg. This means that will be appeared window (maybe Internet Explorer
window or other) there I will see graphic file g1234.jpg.

I will appreciate any your help.
Lado
 
Lado,

Try the following code in the code module for the appropriate
worksheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim WS As Worksheet
Set WS = ActiveSheet
WS.OLEObjects("Image1").Object.Picture = _
LoadPicture(ThisWorkbook.Path & "\" & Target.Text &
".jpg")

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Or, more robust,

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim WS As Worksheet
Dim FName As String
If Not Application.Intersect(Range("A1:A10"), Target) _
Is Nothing Then
FName = ThisWorkbook.Path & "\" & Target.Text & ".jpg"
If Dir(FName) <> "" Then
Set WS = ActiveSheet
WS.OLEObjects("Image1").Object.Picture = _
LoadPicture(FName)
End If
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top