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

tomdentonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hello_everybodyCommented:
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

tomdentonAuthor Commented:
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
hello_everybodyCommented:
Try this:

If origWd <> 0 Then

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomdentonAuthor Commented:
Many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.