Z
ZipCurs
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.
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.