Filename -> Image

  • Thread starter Thread starter Andreas Koch
  • Start date Start date
A

Andreas Koch

Hi,

i have a CSV file with with entries like

Item1;100;c:\pics\item1.gif
Item2;142;c:\pics\item2.gif
Item3;555;c:\pics\item3.gif
....

I'd like to see the actual picture instead of the
filename in the third row. Manual insert/graphic
for each one is too much work.
No clue of scripting yet :-)

Any suggestions what to do?
 
One way to do it is to open your .csv file and then run a macro that does the
real work.

It looks like column C will contain the name of the picture.

Option Explicit
Sub testme01()

Dim myPict As Picture
Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myRng = .Range("C1", .Cells(.Rows.Count, "C").End(xlUp))
For Each myCell In myRng.Cells
With myCell
If Trim(.Value = "") Then
'do nothing
ElseIf Dir(.Value) = "" Then
.Offset(0, 1).Value = "Not Found"
Else
Set myPict = .Parent.Pictures.Insert(.Value)
With myCell.Offset(0, 1)
myPict.Top = .Top
myPict.Left = .Left
myPict.Width = .Width
myPict.Height = .Height
myPict.Name = "Pict_" & .Address(0, 0)
myPict.Placement = xlMoveAndSize
End With
End If
End With
Next myCell
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
click on Tools|macro|macros...
click on the macro name (testme01--but you could rename it to something
meaningful!)
and then click run.
 
Dave said:
One way to do it is to open your .csv file and then run a macro that does the
real work.

Thanks Dave, that (with a little adjustment for my needs) did it :-)
 
Back
Top