Link to home
Start Free TrialLog in
Avatar of tomdenton
tomdenton

asked on

How can I resize all the pictures in a Word 2010 document

Hi

I have a huge document with hundreds of inline images that I want to set to be the same size eg 8cm wide and the aspect remains the same - just as if I had dragged each image to size or used the Picture tools/format/width box.
The following seems to work as a pixel size but I would like to set size as cm (the default in my document) and keep the resolution the same:

Sub ResizeAllImages()
' make all inline images
' 220px wide while preserving aspect ratio

Dim oILShp As InlineShape

For Each oILShp In ActiveDocument.InlineShapes
oILShp.LockAspectRatio = msoTrue
oILShp.Width = 220
'If MsgBox("Continue?", vbYesNo) = vbNo Then Exit For
Next
End Sub

Thanks, Tom

Avatar of hello_everybody
hello_everybody
Flag of South Africa image

This should work.
Sub ResizeAllImages()
' make all inline images
' 8 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(8))
.Width = CentimetersToPoints(8)
End With
Next

For Each oILShp In ActiveDocument.InlineShapes
With oILShp
.Height = AspectHt(.Width, .Height, _
CentimetersToPoints(8))
.Width = CentimetersToPoints(8)
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

Open in new window

Avatar of tomdenton
tomdenton

ASKER

Many thanks, should the line in the function: "If origWd  0 Then" a type?

I tried:  If origWd = 0 Then   but get a runtime error

I tried: If origWd > 0 Then   but then all images size to 8x8
ASKER CERTIFIED SOLUTION
Avatar of hello_everybody
hello_everybody
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks