View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default insert images/pictures

This is similar code to the code I posted in your last request. Adjust the
PictureHeight constant as necessary. file names should be complete path
names such as c:\temp\abc.bmp. No quotes or other character are required in
the file name of the pictures.

The code deletes all old pictures and then adds all the pictures. It is not
easy to only delete the pictures that have changed.

Sub add_pictures()

Const PictureHeight = 25

'delete pictures
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture Then
shp.Delete
End If
Next shp

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Rows(2).RowHeight = PictureHeight

For Each cell In Range("B1:K1")
If cell < "" Then
Set pict = ActiveSheet.Pictures. _
Insert(cell.Value)
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pict.Top = cell.Offset(1, 0).Top
pict.Left = cell.Offset(1, 0).Left
End If
Next cell

End Sub

" wrote:

Hi All,

I need help!!!
I have an excel file, the worksheet from cell B1 through K1 has file
names, all different names. I would like to be able to run a macro
that will insert images in the cells right below the file names in
cells B2 through K2, and incase there is no file name in that column
then leave that cell empty. the pictures need to be made smaller but
when sizing it should keep the ratio.
also the file names could be changing monthly so when the file names
change and I run the macro again then the old pictures should be
deleted first and then insert the new ones.
I would greatly appreciate if any one could help me with this, I
reallu need this.
Thanks in advance.