Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Inline shape / height (Word XP)

    I'm having trouble adjusting the height of a picture which I'm inserting into a document. The picture is inserted at bookmark "SmallLogo" which is col 3 of a table in the footer of section 2. (Col 1 of the table already contains an image.) My code inserts the image as expected, and the height is set to .4"... but the ratio of height:width is not maintained.

    Code is below. Am I missing something?

    Thanks,
    Richard Barrett


    (sLogoFile is defined as the image name. )

    Set rng = ActiveDocument.Bookmarks("SmallLogo").Range
    rng.InlineShapes.AddPicture FileName:= _
    sLogoFile, LinkToFile:=False, _
    SaveWithDocument:=True
    DoEvents
    With ActiveDocument.Sections(2).Footers(wdHeaderFooterF irstPage).Range.InlineShapes(2)
    .LockAspectRatio = msoTrue
    .Height = InchesToPoints(0.4)
    End With

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inline shape / height (Word XP)

    Setting the Height property explicitly makes Word ignore the LockAspectRatio property.

    You could use

    Dim rng As Range
    Dim f As Single
    Set rng = ActiveDocument.Bookmarks("SmallLogo").Range
    With rng.InlineShapes.AddPicture(FileName:=sLogoFile, LinkToFile:=False, SaveWithDocument:=True)
    f = InchesToPoints(0.4) / .Height
    .Height = InchesToPoints(0.4)
    .Width = f * .Width
    End With

    or

    Dim rng As Range
    Dim f As Single
    Set rng = ActiveDocument.Bookmarks("SmallLogo").Range
    With rng.InlineShapes.AddPicture(FileName:=sLogoFile, LinkToFile:=False, SaveWithDocument:=True)
    f = InchesToPoints(0.4) / .Height * 100
    .ScaleHeight = f
    .ScaleWidth = f
    End With

  3. #3
    Star Lounger
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Inline shape / height (Word XP)

    I need to do something similar, but don't quite see how to tweak this code to fit. I have a series of documents with many pictures which need to be resized to the same height -- say two inches for a given project -- with their aspect ratios kept. [I was WONDERING why the LockAspectRatio wasn't working when I managed to resize the height; thank you for explaining that!]

    Selection.InlineShapes(1).Height = 144#
    Selection.InlineShapes(1).LockAspectRatio = msoTrue

    scaled pictures to two inches high and I now see that the second line might as well have been a wistful hope!

    Ideally, I need to select all the pictures in the document and resize each to 2 inches /144 points high while scaling their aspect ratios.

    I follow setting "f" to the original height and then calculating what the new width should be, just not how to use it effectively in a document which has many inline shapes of different sizes and h/w ratios, but no bookmarks and no specific file names for the pictures.

    Many thanks,

    Ann

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inline shape / height (Word XP)

    Try this:

    Sub ResizeInlineShapes()
    Dim shp As InlineShape
    Dim f As Double
    For Each shp In ActiveDocument.InlineShapes
    f = shp.Width / shp.Height
    shp.Height = InchesToPoints(2)
    shp.Width = f * shp.Height
    Next shp
    End Sub

  5. #5
    Star Lounger
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Inline shape / height (Word XP)

    Elegant. Simple. Works perfectly.

    Many, many thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •