Forum Discussion

seanmccole's avatar
seanmccole
Copper Contributor
Feb 17, 2022
Solved

Create a macro to crop images

Hi,   I'm trying to create a macro to crop an image to 1:1 ratio but I'm not sure if its possible.  I'm constantly cropping images and resizing them and it would unbelievably benefit my workflow i...
  • Doug_Robbins_Word_MVP's avatar
    Doug_Robbins_Word_MVP
    Feb 20, 2022

    seanmccole The information on using those properties is pretty sparse, but after a few attempts, I believe the applicable property is the .PictureFormat.Crop.PictureOffsetX and that the offset is from the center of the picture.  For the result that you want, probably no offset is required.

     

    Using the following code with an image that was distorted to the size of your image:

     

    With ActiveDocument
        For i = 1 To .InlineShapes.Count
           With .InlineShapes(i)
               .PictureFormat.Crop.ShapeWidth = .Height
               .PictureFormat.Crop.ShapeHeight = .Height
               .PictureFormat.Crop.PictureOffsetY = 0
               .PictureFormat.Crop.PictureOffsetX = 0
           End With
        Next i
    End With

     

    the result shown compared to an uncropped version of the image

    Increasing the offset, by using

    .PictureFormat.Crop.PictureOffsetX = 10

    reduces the crop from the left

    and reducing it by using

    .PictureFormat.Crop.PictureOffsetX = -10

    increases the crop from the left

     

     

     

     

Resources