View Single Post
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Simon[_2_] Simon[_2_] is offline
external usenet poster
 
Posts: 8
Default Creating a macro in word to resize an image

Jay you are the man.

I owe you a pint for all the work I'll save here.




"Jay Freedman" wrote in message
...
Simon wrote:
Jay thanks for your reply

Just to qualify exactly what I need:

1. All images are inline with text

2. I don't actually want the macro to run on all images in the
document, I only want to run it on an image I have selected (some are
less than 11cm that I want to keep that way plus I need to check each
image individually).
Really appreciate the help

Simon

OK, here's a modified version that handles only inline images, and only
those that are selected -- you can select a chunk of text that includes
more than one image and the macro will change them all.

Sub ResizeSelectedImage()
' make selected inline images
' 11 cm wide while preserving aspect ratio

Dim oILShp As InlineShape

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

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.