PC Review


Reply
Thread Tools Rate Thread

Centering picture in Excel 2007

 
 
ZipCurs
Guest
Posts: n/a
 
      19th Mar 2008
I have some code that sizes and centers an image in a target cell. This
works great in Excel 2000 and 2003. Unfortunately, it only does 75% of the
job in Excel 2007. The scaling and horizontal position are good, but the
vertical position is slightly off. Is there some difference in 2007 that I
need to compensate for?

Thank you in advance. The code is listed below:

'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
 
Reply With Quote
 
 
 
 
ZipCurs
Guest
Posts: n/a
 
      19th Mar 2008
Further investigation shows that final position does indeed have the
calculated value even though the visual position of the image is wrong. In
atleast one case the top of the imported image is above the cell border, even
though the .Top value is greater. Note that I am importing JPEG images of
scanned sketches, although I can't imaging how that would make any
difference.

"ZipCurs" wrote:

> I have some code that sizes and centers an image in a target cell. This
> works great in Excel 2000 and 2003. Unfortunately, it only does 75% of the
> job in Excel 2007. The scaling and horizontal position are good, but the
> vertical position is slightly off. Is there some difference in 2007 that I
> need to compensate for?
>
> Thank you in advance. The code is listed below:
>
> '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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering Picture eddie57 Microsoft Powerpoint 7 4th Dec 2008 12:31 AM
Centering a picture in a worksheet =?Utf-8?B?amZn?= Microsoft Excel Misc 4 17th Aug 2007 03:14 AM
Excel 2007 Beta 2: Chart Title Centering Suggestion =?Utf-8?B?ZHp1eQ==?= Microsoft Excel Charting 1 6th Jun 2006 10:16 PM
problem centering picture in Word Alexander Baron Microsoft Word New Users 2 29th Mar 2005 02:02 AM
Centering picture between columns Maria Microsoft Word New Users 2 16th Nov 2003 02:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:13 PM.