View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Creating a macro in word to resize an image

Simon wrote:
Hi

I am trying to record a macro in Word 2003 which will resize an
images width to 11cm.

The trouble is, the images are all different dimensions, so I need to
lock the aspect ratio for the height.

Whenever I try to record a macro, it always reverts to a fixed height.

Please help.

PS I don't know any VB


It will be impossible to create such a macro strictly by recording. Since
you don't know any VB, either you'll have to learn some, or you can work
with us a bit to get what you need.

You don't say whether the images you're resizing are in line with text or
floating, which makes a big difference in the world of VBA. So the following
macro does both kinds, and simply does nothing if there are no images of one
kind or the other. You can simplify the macro if you only use one kind, but
it won't make a big difference if you don't simplify it.

Also, the macro makes all images 11 cm wide. It doesn't have any way to say
"... except this one". If you want the macro to apply only to the one
specific image that's currently selected, that will take a different macro
(not too different, but...). If you change your mind about the size, that's
easy: change the number in the parentheses after CentimetersToPoints in four
places.

Sub ResizeAllImages()
' make all images (both inline and floating)
' 11 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(11))
.Width = CentimetersToPoints(11)
End With
Next

For Each oILShp In ActiveDocument.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

Post back if this doesn't solve the problem.

If you decide you want to learn enough to modify the macro on your own, read
http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm.

--
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.