Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Insert Picture into a cell | Excel Discussion (Misc queries) | |||
How do I insert a picture into a cell? | Excel Worksheet Functions | |||
How do I insert a picture into a cell? | Excel Discussion (Misc queries) | |||
how do I insert picture into cell so vlookup can return picture? | Excel Worksheet Functions | |||
how to insert picture to the cell? | Excel Discussion (Misc queries) |