View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ZipCurs ZipCurs is offline
external usenet poster
 
Posts: 103
Default Excel 2007 and inserted images

Jim,

Thanks for looking at this. Did you run it in Excel 2007? I know that the
file and macro itself work great to center the image when run in Excel
2000/2003 and that the images do not move when the file is opened on
different computers with different versions of Excel. It most definately is
putting the file in the wrong spot on my computer with Excel 2007 running. I
have already confirmed that the math in the macro is being calculated
properly and the resulting .Top value is the same in Excel 2000 and 2007, the
images are just in physically different places. The differences are big
enough to mess up the way my macros run. I can incrementally move the image
to the spot I want it to be at, but that seems kind of ridiculous and
dangerous, since I don't know why the image is not in the right place to
being with.

Any thoughts would be welcome.

"Jim Rech" wrote:

I've run your code repeatedly and, as far as I can, it centers a picture
perfectly in a cell. I've attached my example. After the button is clicked
the picture is centered in cell E12.

--
Jim
"ZipCurs" wrote in message
...
| Hello,
|
| I input a question yesterday with no responses. My previously functional
| macro no longer centers imported JPG pictures in cells properly in 2007.
| Limited exploration suggests that the code below places the image 5-10
points
| too high, which seems to be enough to put the image "outside" of the cell
| during the sorting I need to do.
|
| 'Scale correctly
| HeightRatio = ActiveSheet.Shapes(ActivePicture).Height / Cells(TargetLine,
| 6).Height
| WidthRatio = ActiveSheet.Shapes(ActivePicture).Width / Cells(TargetLine,
| 6).Width
|
| If HeightRatio = WidthRatio Then
| ActiveSheet.Shapes(ActivePicture).Select
| Selection.ShapeRange.Height = 0.95 *
| ActiveSheet.Shapes(ActivePicture).Height / HeightRatio
| Else
| ActiveSheet.Shapes(ActivePicture).Select
| Selection.ShapeRange.Width = 0.95 *
| ActiveSheet.Shapes(ActivePicture).Width / WidthRatio
| End If
|
| 'Position picture correctly
| With ActiveSheet.Shapes(ActivePicture)
| .Top = Cells(TargetLine, 6).Top + (Cells(TargetLine, 6).Height -
| .Height) / 2
| .Left = Cells(TargetLine, 6).Left + (Cells(TargetLine, 6).Width -
| .Width) / 2
| End With
|
| I have come up with a lame solution that involves looking at what cell the
| TopLeft and BottomRight are in and moving the image slowly until it
changes
| to the correct cell and then moving by the appropriate amount to center.
|
| I would love to have a simpler solution to the Excel 2007 problem, and,
more
| importantly, have a better understanding of why the images are not going
| where I want them to go.
|
| Thank you in advance