Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Inserting Pictures Based On File name

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

.................................................. .................................................. ...................


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Inserting Pictures Based On File name

Not sure if will assist or hinder, but i use the following code to input a picture into a sheet
based on Cell(A1):

' Photo 1
Application.ScreenUpdating = False
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim mypic As Picture
Dim res As Variant
Set WB = ActiveWorkbook
res = sheet1.Range("A1").value
If res = False Then Exit Sub
Set SH = ActiveSheet
Set rng = ActiveCell
Set mypic = SH.Pictures.Insert(res)
With mypic
.Top = rng.Top
.Left = rng.Left
.Locked = False
mypic.ShapeRange.LockAspectRatio = msoFalse
mypic.ShapeRange.Height = 213.1
mypic.ShapeRange.Width = 249.2
mypic.ShapeRange.Rotation = 0#
End With
End If

Corey....

"Jeff W." wrote in message ...
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

.................................................. .................................................. ...................



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you export pictures from my pictures file into a word docu Becky New Users to Excel 1 November 20th 09 07:02 PM
Inserting Pictures cjohnson Excel Discussion (Misc queries) 2 April 2nd 08 07:00 PM
Inserting Pictures Matthew[_2_] Excel Discussion (Misc queries) 3 July 14th 07 10:23 AM
Inserting Pictures Help Please Chris Hankin[_3_] Excel Programming 0 March 27th 07 10:59 AM
inserting more than 65536 pictures into file using VBA maple3 Excel Programming 6 April 30th 06 01:02 AM


All times are GMT +1. The time now is 12:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"