Reply
 
Thread Tools Display Modes
  #1   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

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


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


  #3   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 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



"Jay Freedman" wrote in message
...
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.



  #4   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:
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.


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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. Recording a Macro to resize maintaining aspect ratio Simon[_2_] Microsoft Word Help 4 December 11th 08 03:25 PM
stop creating duplicate image files in word Mack Microsoft Word Help 1 June 28th 08 05:08 AM
how do I show & resize a JPG image in normal view by dragging Phil Page Layout 1 January 9th 07 07:53 AM
Cells that don't resize when image/text inserted [email protected] Tables 1 June 22nd 06 10:00 AM
Web page window resize is changing the text & image layout... R.George Page Layout 1 December 28th 05 04:34 PM


All times are GMT +1. The time now is 07:51 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"