![]() |
Positioning pictures in a cell
I have a table with pictures (jpegs) and descriptions. I would like to use a
macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
Try looking at the "TopLeftCell" property (applies to your pictures).
Alternatively, if you really need to center the picture, cells have top, left, height and width properties which you can use to position your pics. Tim "ZipCurs" wrote in message ... I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
The picture is always smaller than the cell?
with activesheet.Shapes("Picture1") .Top = range("B9").Top + ( range("B9").Height - .height)/2 .Left = range("B9").Left + (range("B9").Width - .Width)/2 End With -- Regards, Tom Ogilvy "ZipCurs" wrote in message ... I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
Both cells and pictures have .Top and .Left properties, that define their
location, and .Width and .Height properties that define their size. For example, if I wanted to put a picture (MyPic) inside cell B2, have it sized at 90% of the cell size and be centered in the cell, this is what I would do: With Range("B2") MyPic.Width = 0.9 * .Width MyPic.Height = 0.9 * .Height MyPic.Top = .Top + 0.05 * .Height ' For picture 90% of height, this will center it top to bottom MyPic.Width = .Left + 0.05 * .Width End With (Note this assumes the aspect ratio of the picture is not locked. It is possible to do the reverse: to fit the cell to the size of the picture) -- - K Dales "ZipCurs" wrote: I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
Hit Close before I fixed a mistake I spotted: last line before End With
should be MyPic.Left=, not MyPic.Width= -- - K Dales "ZipCurs" wrote: I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
Tom,
Exactly what I needed, thanks!!! "Tom Ogilvy" wrote: The picture is always smaller than the cell? with activesheet.Shapes("Picture1") .Top = range("B9").Top + ( range("B9").Height - .height)/2 .Left = range("B9").Left + (range("B9").Width - .Width)/2 End With -- Regards, Tom Ogilvy "ZipCurs" wrote in message ... I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
Positioning pictures in a cell
Very helpful, Thanks
"K Dales" wrote: Both cells and pictures have .Top and .Left properties, that define their location, and .Width and .Height properties that define their size. For example, if I wanted to put a picture (MyPic) inside cell B2, have it sized at 90% of the cell size and be centered in the cell, this is what I would do: With Range("B2") MyPic.Width = 0.9 * .Width MyPic.Height = 0.9 * .Height MyPic.Top = .Top + 0.05 * .Height ' For picture 90% of height, this will center it top to bottom MyPic.Width = .Left + 0.05 * .Width End With (Note this assumes the aspect ratio of the picture is not locked. It is possible to do the reverse: to fit the cell to the size of the picture) -- - K Dales "ZipCurs" wrote: I have a table with pictures (jpegs) and descriptions. I would like to use a macro to insert the picture in the cell next to the description and center it in the cell. I can easily get it near the cell, but I can't seem to find a way to position the picture exactly where it want it. Any help appreciated. |
All times are GMT +1. The time now is 04:30 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com