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 Help. Recording a Macro to resize maintaining aspect ratio

Hi there,

I have a document with lots of images that are too big. I am trying to
resize them all to 11cm wide and maintain the aspect ratio for the height.
I recorded a basic macro but the height is equal to whatever measurement was
in there when I recorded.

Any way around this please!!!

Thanks

Simon


  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Brian Brian is offline
external usenet poster
 
Posts: 298
Default Help. Recording a Macro to resize maintaining aspect ratio

This code was given to me in answer to my question on the same subject by
Stefan

Sub PictSize()
Dim HieghtSize As Integer
Dim oIshp As InlineShape
Dim oshp As Shape
HeightSize = InputBox("Enter height ", "Resize Picture", 11)
For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.LockAspectRatio = msoTrue
'Here's the modified line of code:
.Height = CentimetersToPoints(HeightSize)
End With
Next oIshp
End Sub

Hope it helps

--
Brian McCaffery


"Simon" wrote:

Hi there,

I have a document with lots of images that are too big. I am trying to
resize them all to 11cm wide and maintain the aspect ratio for the height.
I recorded a basic macro but the height is equal to whatever measurement was
in there when I recorded.

Any way around this please!!!

Thanks

Simon



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
DeanH DeanH is offline
external usenet poster
 
Posts: 1,862
Default Help. Recording a Macro to resize maintaining aspect ratio

Hello Simon and Brian.
Unfortuantely this macro is set for height and does not maintain ratio. I am
sure with minor tinkering this will work.
In the mean time I have the below macro which I got from someone on this
forum sometime ago (cannot remember for the moment) and this does work.

TIP: This macro will only change images that are InLineWithText and not
floating. If the images are floating (ie not set with the InLineWithText) the
you can
use the Select Multiple Objects (the icon is found on the Drawing Toolbar
under Customize).
Beware this may select objects you don't want to change, so tread carefully
- maybe work on a copy of the document.

If the Images are InLineWith then the following macro will change all in one
click.

Sub ResizePictureWidth()
' Macro to Resize ALL pictures in the document

Dim inshpPower As InlineShape
Dim sngOldWidth As Single
Const sngNewWidth As Single = 13.5
With ActiveDocument
If .InlineShapes.Count 0 Then
For Each inshpPower In .InlineShapes
With inshpPower
sngOldWidth = .Width
.Width = CentimetersToPoints(sngNewWidth)
.Height = CentimetersToPoints(((.Height * sngNewWidth) /
sngOldWidth))
End With
Next
Else
MsgBox "There are no shapes in this document.", _
vbExclamation, "Cancelled"
End If
End With
End Sub

This macro is set for 13.5cm (my text margin width), so you may need to
change this for your needs.
See http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm for help with macros.
You don't say want Word version you are using, the above is mainly for 2003
and prior but will indicate were to go with 2007.
Hope this helps
DeanH



"Brian" wrote:

This code was given to me in answer to my question on the same subject by
Stefan

Sub PictSize()
Dim HieghtSize As Integer
Dim oIshp As InlineShape
Dim oshp As Shape
HeightSize = InputBox("Enter height ", "Resize Picture", 11)
For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.LockAspectRatio = msoTrue
'Here's the modified line of code:
.Height = CentimetersToPoints(HeightSize)
End With
Next oIshp
End Sub

Hope it helps

--
Brian McCaffery


"Simon" wrote:

Hi there,

I have a document with lots of images that are too big. I am trying to
resize them all to 11cm wide and maintain the aspect ratio for the height.
I recorded a basic macro but the height is equal to whatever measurement was
in there when I recorded.

Any way around this please!!!

Thanks

Simon



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Simon[_2_] Simon[_2_] is offline
external usenet poster
 
Posts: 8
Default Help. Recording a Macro to resize maintaining aspect ratio

Thank you both for your work... much appreciated.

"DeanH" wrote in message
news
Hello Simon and Brian.
Unfortuantely this macro is set for height and does not maintain ratio. I
am
sure with minor tinkering this will work.
In the mean time I have the below macro which I got from someone on this
forum sometime ago (cannot remember for the moment) and this does work.

TIP: This macro will only change images that are InLineWithText and not
floating. If the images are floating (ie not set with the InLineWithText)
the
you can
use the Select Multiple Objects (the icon is found on the Drawing Toolbar
under Customize).
Beware this may select objects you don't want to change, so tread
carefully
- maybe work on a copy of the document.

If the Images are InLineWith then the following macro will change all in
one
click.

Sub ResizePictureWidth()
' Macro to Resize ALL pictures in the document

Dim inshpPower As InlineShape
Dim sngOldWidth As Single
Const sngNewWidth As Single = 13.5
With ActiveDocument
If .InlineShapes.Count 0 Then
For Each inshpPower In .InlineShapes
With inshpPower
sngOldWidth = .Width
.Width = CentimetersToPoints(sngNewWidth)
.Height = CentimetersToPoints(((.Height * sngNewWidth)
/
sngOldWidth))
End With
Next
Else
MsgBox "There are no shapes in this document.", _
vbExclamation, "Cancelled"
End If
End With
End Sub

This macro is set for 13.5cm (my text margin width), so you may need to
change this for your needs.
See http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm for help with
macros.
You don't say want Word version you are using, the above is mainly for
2003
and prior but will indicate were to go with 2007.
Hope this helps
DeanH



"Brian" wrote:

This code was given to me in answer to my question on the same subject by
Stefan

Sub PictSize()
Dim HieghtSize As Integer
Dim oIshp As InlineShape
Dim oshp As Shape
HeightSize = InputBox("Enter height ", "Resize Picture", 11)
For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.LockAspectRatio = msoTrue
'Here's the modified line of code:
.Height = CentimetersToPoints(HeightSize)
End With
Next oIshp
End Sub

Hope it helps

--
Brian McCaffery


"Simon" wrote:

Hi there,

I have a document with lots of images that are too big. I am trying to
resize them all to 11cm wide and maintain the aspect ratio for the
height.
I recorded a basic macro but the height is equal to whatever
measurement was
in there when I recorded.

Any way around this please!!!

Thanks

Simon





  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Simon[_2_] Simon[_2_] is offline
external usenet poster
 
Posts: 8
Default Help. Recording a Macro to resize maintaining aspect ratio

Just as a side note, will this run on all the pictures in the document or
selected images? I ask because some are smaller than 11cm wide and I don't
want to resize those.

Many many thanks

Simon





"Simon" wrote in message
...
Thank you both for your work... much appreciated.

"DeanH" wrote in message
news
Hello Simon and Brian.
Unfortuantely this macro is set for height and does not maintain ratio. I
am
sure with minor tinkering this will work.
In the mean time I have the below macro which I got from someone on this
forum sometime ago (cannot remember for the moment) and this does work.

TIP: This macro will only change images that are InLineWithText and not
floating. If the images are floating (ie not set with the InLineWithText)
the
you can
use the Select Multiple Objects (the icon is found on the Drawing Toolbar
under Customize).
Beware this may select objects you don't want to change, so tread
carefully
- maybe work on a copy of the document.

If the Images are InLineWith then the following macro will change all in
one
click.

Sub ResizePictureWidth()
' Macro to Resize ALL pictures in the document

Dim inshpPower As InlineShape
Dim sngOldWidth As Single
Const sngNewWidth As Single = 13.5
With ActiveDocument
If .InlineShapes.Count 0 Then
For Each inshpPower In .InlineShapes
With inshpPower
sngOldWidth = .Width
.Width = CentimetersToPoints(sngNewWidth)
.Height = CentimetersToPoints(((.Height * sngNewWidth)
/
sngOldWidth))
End With
Next
Else
MsgBox "There are no shapes in this document.", _
vbExclamation, "Cancelled"
End If
End With
End Sub

This macro is set for 13.5cm (my text margin width), so you may need to
change this for your needs.
See http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm for help with
macros.
You don't say want Word version you are using, the above is mainly for
2003
and prior but will indicate were to go with 2007.
Hope this helps
DeanH



"Brian" wrote:

This code was given to me in answer to my question on the same subject
by
Stefan

Sub PictSize()
Dim HieghtSize As Integer
Dim oIshp As InlineShape
Dim oshp As Shape
HeightSize = InputBox("Enter height ", "Resize Picture", 11)
For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.LockAspectRatio = msoTrue
'Here's the modified line of code:
.Height = CentimetersToPoints(HeightSize)
End With
Next oIshp
End Sub

Hope it helps

--
Brian McCaffery


"Simon" wrote:

Hi there,

I have a document with lots of images that are too big. I am trying
to
resize them all to 11cm wide and maintain the aspect ratio for the
height.
I recorded a basic macro but the height is equal to whatever
measurement was
in there when I recorded.

Any way around this please!!!

Thanks

Simon







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
Lock Aspect Ratio? - What does that mean? TB in DC Microsoft Word Help 5 April 21st 23 02:21 PM
I need to change the aspect ratio john@trophy Microsoft Word Help 1 July 8th 07 07:49 PM
Recording a Macro dorita Microsoft Word Help 1 October 17th 06 06:59 AM
Possible bug when recording a Word Macro Raven95 Microsoft Word Help 4 April 30th 05 09:49 PM
Want the Word ruler to be real, and the aspect ratio. jph246 Microsoft Word Help 1 January 4th 05 07:55 AM


All times are GMT +1. The time now is 02:45 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"