+ Reply to Thread
Results 1 to 3 of 3

Code to resize images maintaining ratio

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-31-2008
    Location
    Berkshire, UK
    MS-Off Ver
    2003 & 2007
    Posts
    118

    Code to resize images maintaining ratio

    Hi there.

    I once had a macro which was built for me, that resized the width of an image to 11cm whilst maintaining the ratio of the height.

    I am not very experienced at all in coding my own Macros. I have tried recording one to achieve this but the image never resizes the height correctly, it always resizes to the measurement of the picture that I resized whilst recording the macro.


    Work have chucked away my old computer and I have lost all my lovely Macros

    Can anyone help?
    Last edited by simjambra; 08-05-2009 at 06:30 PM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Code to resize images maintaining ratio

    from here
    http://www.pcreview.co.uk/forums/thread-3732765.php
    insert into a new module(alt +f11 to open editor,then insert/ module
    paste the code in)
    Sub ResizeAllImages()
    ' make all images (both inline and floating)
    ' 11 cm wide while preserving aspect ratio
    
    Dim oShp As Shape
    Dim oILShp As InlineShape
    
    For Each oShp In ActiveDocument.Shapes
    With oShp
    .Height = AspectHt(.Width, .Height, _
    CentimetersToPoints(11))
    .Width = CentimetersToPoints(11)
    End With
    Next
    
    For Each oILShp In ActiveDocument.InlineShapes
    With oILShp
    .Height = AspectHt(.Width, .Height, _
    CentimetersToPoints(11))
    .Width = CentimetersToPoints(11)
    End With
    Next
    End Sub
    
    Private Function AspectHt( _
    origWd As Long, origHt As Long, _
    newWd As Long) As Long
    If origWd <> 0 Then
    AspectHt = (CSng(origHt) / CSng(origWd)) * newWd
    Else
    AspectHt = 0
    End If
    End Function
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Contributor
    Join Date
    07-31-2008
    Location
    Berkshire, UK
    MS-Off Ver
    2003 & 2007
    Posts
    118

    Re: Code to resize images maintaining ratio

    That's great, thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1