Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 | |
|
|
![]() |
||||
Thread | Forum | |||
Help. Recording a Macro to resize maintaining aspect ratio | Microsoft Word Help | |||
stop creating duplicate image files in word | Microsoft Word Help | |||
how do I show & resize a JPG image in normal view by dragging | Page Layout | |||
Cells that don't resize when image/text inserted | Tables | |||
Web page window resize is changing the text & image layout... | Page Layout |