Jay
Tue Feb 13 20:38:38 CST 2007
Somewhere in the bowels of the VBA interpreter, the code that handles
.LockAspectRatio is broken. What works in the dialog doesn't work at
all in VBA.
Here's some code from one of my macros to handle proportional
resizing.
' change these numbers to the maximum width and height
' (in inches) to make the inserted pictures
Const PicWidth = 1.9
Const PicHeight = 2.25
Dim Photo As InlineShape
Set Photo = .InlineShapes.AddPicture(FileName:=FName, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=PicRg)
With Photo
RatioW = CSng(InchesToPoints(PicWidth)) / .Width
RatioH = CSng(InchesToPoints(PicHeight)) / .Height
' choose the smaller ratio
If RatioW < RatioH Then
RatioUse = RatioW
Else
RatioUse = RatioH
End If
' size the picture to fit the cell
.Height = .Height * RatioUse
.Width = .Width * RatioUse
End With
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Wed, 14 Feb 2007 00:31:13 +0000, Roderick O'Regan
<rory@removethis.theoregans.com> wrote:
>I want to resize a selected picture using VBA but I only want to
>change the width of the picture to say, 2cm and the height should
>adjust to scale automatically.
>
>Manually, using the Format>Picture command I can achieve this by
>ensuring that Lock aspect ratio checkbox is True.
>
>However, if I translate this to VBA using the following commands:
> with Selection
> .InlineShapes(1).LockAspectRatio = msoTrue
> .InlineShapes(1).Width = CentimetersToPoints(2)
> End With
>...I would expect the same to happen as when I did it manually. Even
>though the Lock aspect ratio is set to True it reduces the width to
>2cm but leaves the height at its original value.
>
>Am I using the correct commands, please?