Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default insert pictures

help please,

I need to insert pictures in excel using macro, I have picture names
in row1 (B1:G1) and I want to insert the pictures to row2 (B2:G2) each
cell has different file name, and I would want the pictures to be
resized to a 32 px and keep the ratio, and if possible be connected to
the cells.

thanks
marc

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default insert pictures

Try this code. Not sure how to reduce quality to 32K format. You need to
specify the height of the pictue in pixels. The program sets the row heigh
and then adjusts the picture size to fit the row height. the picture is
place on the worksheet based on the cells top and left properties. You may
want to make the picture a little bit smaller the then cell height.

pict.ShapeRange.Height = PictureHeight - 10

Also you may want the picture not to be at the top edge of the cell

pict.Top = Range("B" & RowCount).Top + 5


Sub add_pictures()

Const PictureHeight = 100

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

For RowCount = 1 To LastRow
Set pict = ActiveSheet.Pictures.Insert(Range("A" & RowCount))
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pict.Top = Range("B" & RowCount).Top
pict.Left = Range("B" & RowCount).Left
Next RowCount

End Sub
" wrote:

help please,

I need to insert pictures in excel using macro, I have picture names
in row1 (B1:G1) and I want to insert the pictures to row2 (B2:G2) each
cell has different file name, and I would want the pictures to be
resized to a 32 px and keep the ratio, and if possible be connected to
the cells.

thanks
marc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default insert pictures

On Oct 28, 1:50 am, Joel wrote:
Try this code. Not sure how to reduce quality to 32K format. You need to
specify the height of the pictue in pixels. The program sets the row heigh
and then adjusts the picture size to fit the row height. the picture is
place on the worksheet based on the cells top and left properties. You may
want to make the picture a little bit smaller the then cell height.

pict.ShapeRange.Height = PictureHeight - 10

Also you may want the picture not to be at the top edge of the cell

pict.Top = Range("B" & RowCount).Top + 5

Sub add_pictures()

Const PictureHeight = 100

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

For RowCount = 1 To LastRow
Set pict = ActiveSheet.Pictures.Insert(Range("A" & RowCount))
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pict.Top = Range("B" & RowCount).Top
pict.Left = Range("B" & RowCount).Left
Next RowCount

End Sub



" wrote:
help please,


I need to insert pictures in excel using macro, I have picture names
in row1 (B1:G1) and I want to insert the pictures to row2 (B2:G2) each
cell has different file name, and I would want the pictures to be
resized to a 32 px and keep the ratio, and if possible be connected to
the cells.


thanks
marc- Hide quoted text -


- Show quoted text -


Thanks, but I can not get it to work, what should I do?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default insert pictures

There is really no reason this code shouldn't work without any changes. I
fully tested the code with my version of excel 2003.

1) Make sure code is in a VBA module for the workbook that contains the
filenames in column A
2) Make sure the worksheet with the filenames are the active worksheet
3) the filenames should be complete paths with extensions such as

c:\temp\joel.bmp or c:\joel\joel.jpg

You didn't give any error information so I'm not sure of the problem.

" wrote:

On Oct 28, 1:50 am, Joel wrote:
Try this code. Not sure how to reduce quality to 32K format. You need to
specify the height of the pictue in pixels. The program sets the row heigh
and then adjusts the picture size to fit the row height. the picture is
place on the worksheet based on the cells top and left properties. You may
want to make the picture a little bit smaller the then cell height.

pict.ShapeRange.Height = PictureHeight - 10

Also you may want the picture not to be at the top edge of the cell

pict.Top = Range("B" & RowCount).Top + 5

Sub add_pictures()

Const PictureHeight = 100

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

For RowCount = 1 To LastRow
Set pict = ActiveSheet.Pictures.Insert(Range("A" & RowCount))
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pict.Top = Range("B" & RowCount).Top
pict.Left = Range("B" & RowCount).Left
Next RowCount

End Sub



" wrote:
help please,


I need to insert pictures in excel using macro, I have picture names
in row1 (B1:G1) and I want to insert the pictures to row2 (B2:G2) each
cell has different file name, and I would want the pictures to be
resized to a 32 px and keep the ratio, and if possible be connected to
the cells.


thanks
marc- Hide quoted text -


- Show quoted text -


Thanks, but I can not get it to work, what should I do?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default insert pictures

Thanks
the first error that I get is "Compile error" "Invalid outside
procedure" and the error is for (pict.ShapeRange.Height =
PictureHeight - 10) the (PictureHeight - 10) part.

The second error, "Run-time error '1004': Unable to get the insert
property of the picture class"

Thank You,




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default insert pictures

The sub routine should start with SUB and end with END SUB. the lines above
are modification to the code below SUB to center the picture inside the cell.

" wrote:

Thanks
the first error that I get is "Compile error" "Invalid outside
procedure" and the error is for (pict.ShapeRange.Height =
PictureHeight - 10) the (PictureHeight - 10) part.

The second error, "Run-time error '1004': Unable to get the insert
property of the picture class"

Thank You,



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
Can't insert pictures laurie New Users to Excel 2 April 5th 23 01:21 PM
Insert pictures AZU Excel Discussion (Misc queries) 5 March 6th 09 05:28 PM
Insert pictures dc Excel Programming 2 June 5th 07 06:43 AM
Insert pictures TheRook Excel Programming 4 August 11th 06 02:58 PM
Activesheet.Pictures.Insert dchow Excel Programming 2 September 24th 03 07:22 PM


All times are GMT +1. The time now is 10:28 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"