Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default can i insert a picture in an exact cell of a spreadsheet

is there any method or VBA program to insert a picture in an exact cell in an
excel spreadsheet?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default can i insert a picture in an exact cell of a spreadsheet

Sub Macro1()
Range("B9").Select
Set pic = ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\username\My Documents\My
Pictures\Sample.jpg")
pic.Height = Range("B9").Height
pic.Width = Range("B9").Width

End Sub

should get you started.

--
Regards,
Tom Ogilvy


"ngane" wrote in message
...
is there any method or VBA program to insert a picture in an exact cell in

an
excel spreadsheet?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default can i insert a picture in an exact cell of a spreadsheet

Dim Rng As Range
With Worksheets("Sheet2")
Set Rng = .Range("G17")
.Shapes.AddPicture "C:\tph5000.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

"ngane" wrote in message
...
is there any method or VBA program to insert a picture in an exact cell in
an
excel spreadsheet?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default can i insert a picture in an exact cell of a spreadsheet

Hi

If you want to insert a picture in merged cells, you won't get the results
you expect using Toms example. It works great if you resize the cell to
the size you want the picture to be first, but not for merged cells.

Sharad's example will work on merged cells if modified
to include the first and last cell in the merged cells area like this.

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9:j17")
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

You can also use a named range by defining a name like "PictureRange"
and then using Toms code modified like this .

Range("PictureRange").Select
Set pic = ActiveSheet.Pictures.Insert("C:\pictures\Sample.jp g")
pic.Height = Range("PictureRange").Height
pic.Width = Range("PictureRange").Width

to place the picture in a merged cell range.

You may find that these options give you greater flexibility in laying out
portions of your worksheet.

HTH

Ken


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default can i insert a picture in an exact cell of a spreadsheet

Now, that's valid point.
When inserting picture in a cell, more chances that
one has merged cells.

Thanks Ken,

Sharad

"Ken Macksey" wrote in message
...
Hi

If you want to insert a picture in merged cells, you won't get the results
you expect using Toms example. It works great if you resize the cell to
the size you want the picture to be first, but not for merged cells.

Sharad's example will work on merged cells if modified
to include the first and last cell in the merged cells area like this.

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9:j17")
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

You can also use a named range by defining a name like "PictureRange"
and then using Toms code modified like this .

Range("PictureRange").Select
Set pic = ActiveSheet.Pictures.Insert("C:\pictures\Sample.jp g")
pic.Height = Range("PictureRange").Height
pic.Width = Range("PictureRange").Width

to place the picture in a merged cell range.

You may find that these options give you greater flexibility in laying out
portions of your worksheet.

HTH

Ken






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default can i insert a picture in an exact cell of a spreadsheet

Just to add a slightly different way to handle cells, merged or not.

This works whether the cell is merged or not:

Sub Macro1()
Range("B9").MergeArea.Select
Set pic = ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\username\My Documents\My
Pictures\Sample.jpg")
pic.Height = Range("B9").MergeArea.Height
pic.Width = Range("B9").MergeArea.Width

End Sub

Similarly Sharad's would be modified like this:

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9").MergeArea
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

Then you don't need to know which cells are merged or even if it is merged.


--
Regards,
Tom Ogilvy

"Ken Macksey" wrote in message
...
Hi

If you want to insert a picture in merged cells, you won't get the results
you expect using Toms example. It works great if you resize the cell to
the size you want the picture to be first, but not for merged cells.

Sharad's example will work on merged cells if modified
to include the first and last cell in the merged cells area like this.

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9:j17")
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

You can also use a named range by defining a name like "PictureRange"
and then using Toms code modified like this .

Range("PictureRange").Select
Set pic = ActiveSheet.Pictures.Insert("C:\pictures\Sample.jp g")
pic.Height = Range("PictureRange").Height
pic.Width = Range("PictureRange").Width

to place the picture in a merged cell range.

You may find that these options give you greater flexibility in laying out
portions of your worksheet.

HTH

Ken




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default can i insert a picture in an exact cell of a spreadsheet

Interesting Tom!
Didn't even know that .MergeArea property exists.

Sharad

"Tom Ogilvy" wrote in message
...
Just to add a slightly different way to handle cells, merged or not.

This works whether the cell is merged or not:

Sub Macro1()
Range("B9").MergeArea.Select
Set pic = ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\username\My Documents\My
Pictures\Sample.jpg")
pic.Height = Range("B9").MergeArea.Height
pic.Width = Range("B9").MergeArea.Width

End Sub

Similarly Sharad's would be modified like this:

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9").MergeArea
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

Then you don't need to know which cells are merged or even if it is
merged.


--
Regards,
Tom Ogilvy

"Ken Macksey" wrote in message
...
Hi

If you want to insert a picture in merged cells, you won't get the
results
you expect using Toms example. It works great if you resize the cell to
the size you want the picture to be first, but not for merged cells.

Sharad's example will work on merged cells if modified
to include the first and last cell in the merged cells area like this.

Dim Rng As Range
With Worksheets("Sheet1")
Set Rng = .Range("g9:j17")
.Shapes.AddPicture "C:\pictures\Sample.jpg", msoFalse, _
msoTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height
End With

You can also use a named range by defining a name like "PictureRange"
and then using Toms code modified like this .

Range("PictureRange").Select
Set pic = ActiveSheet.Pictures.Insert("C:\pictures\Sample.jp g")
pic.Height = Range("PictureRange").Height
pic.Width = Range("PictureRange").Width

to place the picture in a merged cell range.

You may find that these options give you greater flexibility in laying
out
portions of your worksheet.

HTH

Ken






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default can i insert a picture in an exact cell of a spreadsheet

Hi Tom

I knew that you would probably have a better way, but that was all I could
come up with that would work. Thanks for the great info as always.

Ken


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
Insert Picture into a cell PSULionRP Excel Discussion (Misc queries) 1 July 15th 09 05:47 PM
How do I insert a picture into a cell? Evan Lapka[_2_] Excel Worksheet Functions 7 June 21st 07 10:18 PM
How do I insert a picture into a cell? Evan Lapka Excel Discussion (Misc queries) 1 June 21st 07 12:05 AM
how do I insert picture into cell so vlookup can return picture? ah Excel Worksheet Functions 1 May 1st 07 04:38 AM
how to insert picture to the cell? Johney Salem Excel Discussion (Misc queries) 2 January 23rd 06 04:58 PM


All times are GMT +1. The time now is 03:53 AM.

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"