Reputation: 28989
I get word 2010 documents containing images. Now for some reason these images are scaled to 133%.
Now I'm looking for a way to iterate through all images in the document and scale them to 100%. I found this script, but it does not work (and I got no clue about word macros, so I don't know why):
Sub AllGraphicsTo100()
Dim ILS As Word.InlineShape
Dim SHP As Word.Shape
For Each ILS In ActiveDocument.InlineShapes
If ILS.Type = wdInlineShapePicture Then
ILS.ScaleHeight = 100
ILS.ScaleWidth = 100
End If
Next ILS
For Each SHP In ActiveDocument.Shapes
If SHP.Type = msoPicture Then
SHP.ScaleHeight 1#, True
SHP.ScaleWidth 1, True
End If
Next SHP
End Sub
Additionally if the images are wider than the column I'd like to scale them to fit the width of the column instead of 100%.
Upvotes: 3
Views: 4797
Reputation: 940
It is possible that your images are linked, rather than embedded. You can modify the macro to include linked images as well like this:
Sub AllGraphicsTo100()
Dim ILS As Word.InlineShape
Dim SHP As Word.Shape
For Each ILS In ActiveDocument.InlineShapes
If ILS.Type = wdInlineShapePicture Or ILS.Type = wdInlineShapeLinkedPicture Then
ILS.ScaleHeight = 100
ILS.ScaleWidth = 100
End If
Next ILS
For Each SHP In ActiveDocument.Shapes
If SHP.Type = msoPicture Or SHP.Type = msoLinkedPicture Then
SHP.ScaleHeight 1#, True
SHP.ScaleWidth 1, True
End If
Next SHP
End Sub
Upvotes: 5