J
Jeff W.
I have this code from another thread posted by Joel, and I want
to find out if it will work for me
On my sheet I have a file name in column A and this is the name of
the file I want to insert automatically into that cell or on top of that
cell.
The number of rows changes from sheet to sheet, and to allow room
for the picture, the rows may be, the first three, then the next three then
the next three
So my sheet may look like this;
ball.bmp | 1 | "need image inserted into cell A1"
|.750 |
| 3.0 |
bull.bmp | 1 | "need image inserted into cell A4"
|.500 |
| 3.5 |
squ .bmp | 1 | "need image inserted into cell A7"
|.375 |
| 3.2 |
etc, etc as long as the sheet might be...
I think, I would be checking every fourth row for a file name
Would this code work or would I be better of using something else?
Thanks
Jeff W.
.......................................................................................................................
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
.......................................................................................................................
to find out if it will work for me
On my sheet I have a file name in column A and this is the name of
the file I want to insert automatically into that cell or on top of that
cell.
The number of rows changes from sheet to sheet, and to allow room
for the picture, the rows may be, the first three, then the next three then
the next three
So my sheet may look like this;
ball.bmp | 1 | "need image inserted into cell A1"
|.750 |
| 3.0 |
bull.bmp | 1 | "need image inserted into cell A4"
|.500 |
| 3.5 |
squ .bmp | 1 | "need image inserted into cell A7"
|.375 |
| 3.2 |
etc, etc as long as the sheet might be...
I think, I would be checking every fourth row for a file name
Would this code work or would I be better of using something else?
Thanks
Jeff W.
.......................................................................................................................
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
.......................................................................................................................