none
Unable to retrieve ScaleHeight from InlineShape (Word 2007) RRS feed

  • Question

  • I need to selectively adjust the size of inlineShapes in my document (using Word 2007).

    Specifically, if the inlineShape has been scaled up (i.e. > 100%), I want to resize it back down to 100%.  If it's been scaled down (< 100%), I want to leave it alone.  Obviously, the ScaleHeight and ScaleWidth properties of the inlineShape exist.  But (in Word 2007 anyway), I can only SET these properties.  If I try to access either (or both) of them, a value of "0" is always returned.

    Is this a bug in Word 2007, or am I missing something?  Is there a workaround (short of using .ConvertToShape)?

    Word clearly knows the "Original Size" of the picture: on the "Format" ribbon, open the popup from the "Size" section and look near the bottom. 

    (I tried doing a "Record Macro" using this popup, keeping the "Relative to Original Size" box checked and setting the Scale factors for both height and width to 100%.  However, the code that resulted from this specified the actual values for height and width that were computed here - as opposed to specifying the scale percentages and relative-to-what information).

    Thanks

    -Ric


    • Edited by Ric_D Friday, April 12, 2013 3:11 PM
    Friday, April 12, 2013 2:20 PM

Answers

  • Unlike Shapes, which have a 'relative to' property, InlineShapes do not have one and do not retain their scalings. Once the document is closed, the saved sizes become the 'original' sizes and the scaling is lost.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, April 12, 2013 11:04 PM
  • Thanks for the info!

    Since I am able to adjust the images in the doc before it is closed, I managed a workaround:  In a loop, I convert each InlineShape to a Shape, selectively adjust the scaling (sizing), and then convert the Shape back to an InlineShape.  (A little kludgy, but it works..!)  Code is below.

    ---

    I am wondering why the code (below) fails without the ils.Select statement (see comment).  Any insights there?

    -Ric

        Dim ils As InlineShape
        Dim shp As Shape
        Dim rr As Range
       
        For Each ils In ActiveDocument.InlineShapes
            ils.Select  ' not sure why this is req'd, but the convert (below) fails without it!
            myWidth = ils.Width
            myHeight = ils.Height
            ils.ConvertToShape
            Set rr = ils.Range.Duplicate
            rr.ShapeRange(1).ScaleHeight 1, msoTrue
            rr.ShapeRange(1).ScaleWidth 1, msoTrue
            If rr.ShapeRange(1).Width > myWidth Then  ' if I got bigger, change it back!
                rr.ShapeRange(1).Width = myWidth
                rr.ShapeRange(1).Height = myHeight   ' not really required, but for completeness...
            End If
            rr.ShapeRange(1).ConvertToInlineShape
            
        Next


    • Marked as answer by Ric_D Monday, April 15, 2013 12:43 PM
    • Edited by Ric_D Monday, April 15, 2013 3:21 PM follow up
    Monday, April 15, 2013 12:41 PM

All replies

  • Unlike Shapes, which have a 'relative to' property, InlineShapes do not have one and do not retain their scalings. Once the document is closed, the saved sizes become the 'original' sizes and the scaling is lost.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, April 12, 2013 11:04 PM
  • Thanks for the info!

    Since I am able to adjust the images in the doc before it is closed, I managed a workaround:  In a loop, I convert each InlineShape to a Shape, selectively adjust the scaling (sizing), and then convert the Shape back to an InlineShape.  (A little kludgy, but it works..!)  Code is below.

    ---

    I am wondering why the code (below) fails without the ils.Select statement (see comment).  Any insights there?

    -Ric

        Dim ils As InlineShape
        Dim shp As Shape
        Dim rr As Range
       
        For Each ils In ActiveDocument.InlineShapes
            ils.Select  ' not sure why this is req'd, but the convert (below) fails without it!
            myWidth = ils.Width
            myHeight = ils.Height
            ils.ConvertToShape
            Set rr = ils.Range.Duplicate
            rr.ShapeRange(1).ScaleHeight 1, msoTrue
            rr.ShapeRange(1).ScaleWidth 1, msoTrue
            If rr.ShapeRange(1).Width > myWidth Then  ' if I got bigger, change it back!
                rr.ShapeRange(1).Width = myWidth
                rr.ShapeRange(1).Height = myHeight   ' not really required, but for completeness...
            End If
            rr.ShapeRange(1).ConvertToInlineShape
            
        Next


    • Marked as answer by Ric_D Monday, April 15, 2013 12:43 PM
    • Edited by Ric_D Monday, April 15, 2013 3:21 PM follow up
    Monday, April 15, 2013 12:41 PM