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 images/pictures

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
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.


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

On Oct 31, 11:51 pm, Joel wrote:
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.- Hide quoted text -


- Show quoted text -


Thank you very much, this worked great.

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

On Oct 31, 10:51 pm, Joel wrote:
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 willinsertimagesin 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 theninsertthe new ones.
I would greatly appreciate if any one could help me with this, I
reallu need this.
Thanks in advance.- Hide quoted text -


- Show quoted text -



Hi, the code worked great but I need to add something to it. First, If
possible I would like to add a code that if picture is not available
or can not find then it should insert a text "Picture not Available".
Second, before it inserts the pictures it should delete all pictures &
text in the row and then insert the pictures. Thank you very much...

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default insert images/pictures

On Nov 5, 5:40 am, wrote:
On Oct 31, 10:51 pm, Joel wrote:



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 willinsertimagesin 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 theninsertthe new ones.
I would greatly appreciate if any one could help me with this, I
reallu need this.
Thanks in advance.- Hide quoted text -


- Show quoted text -


Hi, the code worked great but I need to add something to it. First, If
possible I would like to add a code that if picture is not available
or can not find then it should insert a text "Picture not Available".
Second, before it inserts the pictures it should delete all pictures &
text in the row and then insert the pictures. Thank you very much...


I've just added six lines (commented with 'new line) to Joel's code to
handle unfound pictures...

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
cell.Offset(1, 0).ClearContents
On Error GoTo NoPict 'new line
Set pict = ActiveSheet.Pictures. _
Insert(cell.Value)
If cell.Offset(1, 0).Value < "Picture not Available" Then
'new line
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pict.Top = cell.Offset(1, 0).Top
pict.Left = cell.Offset(1, 0).Left
End If
End If 'new line
Next cell
Exit Sub 'new line

NoPict: cell.Offset(1, 0).Value = "Picture not Available" 'new line
Resume Next 'new line

End Sub


Also, adding to the top of the code...

Application.ScreenUpdating = False

will reduce most of the screen flashing.

Ken Johnson



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
Adding pictures, images or objects darkside7out Excel Discussion (Misc queries) 1 March 10th 10 01:05 AM
Is there a way to insert images into unlocked cells martin Excel Discussion (Misc queries) 1 December 15th 08 10:51 PM
Insert Images Using Conditional Format (Many) Mike Garcia Excel Discussion (Misc queries) 4 October 4th 07 03:25 PM
help please (VBA to insert images) alenhart[_2_] Excel Programming 2 May 7th 06 12:21 AM
I want glitter images to insert rita New Users to Excel 1 February 27th 06 10:00 PM


All times are GMT +1. The time now is 02:54 AM.

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

About Us

"It's about Microsoft Excel"