Share via

Macro to resize Image(s)

Anonymous
2022-12-12T22:11:57+00:00

I have the Home and Student 2016 version, running under Windows 10.

Please help me create a macro that will resize a selected image to a given width, say 3 inches (the height should automatically change to keep the same ratio).

I need to be able to edit the macro to change 3 inches to a different measurement, but that should be easy enough to see how to edit the macro once I have the basic code to perform the resizing.

Additional question - is this possible?: A macro that can resize multiple images. Since I can't figure out a way to select multiple images when they are interspersed with text, I'm guessing this might not be possible.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2022-12-12T22:43:24+00:00

    To resize one picture:

    Sub ResizePic()
        Select Case Selection.Type
          Case wdSelectionShape
            With Selection.ShapeRange
              Select Case .Type
                Case msoPicture, msoLinkedPicture
                  .LockAspectRatio = msoTrue
                  .Width = Application.InchesToPoints(3)
              End Select
            End With
          Case wdSelectionInlineShape
            With Selection.ShapeRange
              Select Case .Type
                Case wdInlineShapeLinkedPicture, wdInlineShapePicture
                  .LockAspectRatio = msoTrue
                  .Width = Application.InchesToPoints(3)
              End Select
            End With
        End Select
    End Sub
    

    To resize all pictures in the document:

    Sub ResizePics()
        Dim shp As Shape
        Dim ish As InlineShape
        For Each shp In ActiveDocument.Shapes
            Select Case shp.Type
              Case msoPicture, msoLinkedPicture
                shp.LockAspectRatio = msoTrue
                shp.Width = Application.InchesToPoints(3)
            End Select
        Next shp
        For Each ish In ActiveDocument.InlineShapes
            Select Case ish.Type
              Case wdInlineShapeLinkedPicture, wdInlineShapePicture
                ish.LockAspectRatio = msoTrue
                ish.Width = Application.InchesToPoints(3)
            End Select
        Next ish
    End Sub
    
    2 people found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2022-12-13T05:42:33+00:00
    1 person found this answer helpful.
    0 comments No comments