Resizing all pictures, bigger than a given size with macro in Microsoft Word 2007?

5,447

One possible way to create this conditional macro is this, using an If to check for the heigth of the selected image. (thanks for the help to Tanya).

Sub SizeAllImage()
Dim pic As Long
With ActiveDocument
For pic = 1 To .InlineShapes.Count
    With .InlineShapes(pic)
 If .Height >= CentimetersToPoints(1) Then
    .Width = CentimetersToPoints(2.3)
End If    
End With
Next pic
End With
End Sub
Share:
5,447

Related videos on Youtube

Maysea
Author by

Maysea

Updated on September 18, 2022

Comments

  • Maysea
    Maysea over 1 year

    I have a Word document with some 5000 pictures. There are two types, ones, that have low height, and others, which are higher. I only want to resize the ones higher than 1 cm to have a width of 2.3 cm. I have macro to resize all the pics, but if there is a way to add condition, which I mentioned, please let me know.

    Here is the macro, I used for resizing all images.

    Sub SizeAllImage()
    Dim pic As Long
    With ActiveDocument
    For pic = 1 To .InlineShapes.Count
        With .InlineShapes(pic)
            .Width = CentimetersToPoints(2.3)
        End With
    Next pic
    End With
    End Sub
    
    • Admin
      Admin about 6 years
      What if you add an IF test to check if height of picture is >=1cm, with the true result being the .Width assignment in your With block. For example, assuming .height is already in points: if .Height>=CentimetersToPoints(1) then .Width=CentimetersToPoints(2.3) –
    • Admin
      Admin about 6 years
      Thanks, this works like a charm. Will you make the answer for this, or should I? To people not really familiar with the vba syntax, here's the final macro, that worked for me: Sub SizeAllImage() Dim pic As Long With ActiveDocument For pic = 1 To .InlineShapes.Count With .InlineShapes(pic) If .Height >= CentimetersToPoints(1) Then .Width = CentimetersToPoints(4.3) End If End With Next pic End With End Sub
    • Admin
      Admin about 6 years
      Happy for you to add answer.