?
Solved

How to create a Macro in MS Word 2003 to resize all images in document

Posted on 2010-11-19
5
Medium Priority
?
550 Views
Last Modified: 2012-05-10
I run a merged fields document every week, this contains a picture on each page and there is 1 picture per page.  All of these pictures come through as different sizes.

I have previously asked people on EE to look at how we can re-code the document to pull through the images the correct size but due to the way the document was developed and how we run the merge this is not possible.

I was wondering as a workaround if something else could be done to resize all images simply rather than manually changing them all.

After a few google searches it appears that a Macro would resolve the problem, however, I have never created a Macro before.

I have found some sample code here:

http://en.allexperts.com/q/Microsoft-Word-1058/Word-resize-pictures.htm

But have no idea how to create a macro, add the code then run it.

Any help on this issue will be greatly appreciated.

Im have not added the document to this post as it contains personal customer data.  If this becomes necessary then i'll work through it and remove all the info.
0
Comment
Question by:auraorange
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Author Comment

by:auraorange
ID: 34172581
If at all possible, I'd like to specify the size of the images in pixels
0
 
LVL 14

Accepted Solution

by:
leoahmad earned 2000 total points
ID: 34172596

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

Open in new window

0
 
LVL 2

Author Comment

by:auraorange
ID: 34172976
Thank you the code is perfect!

I've changed the size perameters and that worked fine.

I still have a problem where the document also contains frames and text boxes and these have also resized but Ill have to probably post a new question for that
0
 
LVL 14

Expert Comment

by:leoahmad
ID: 34173023
Better you do that as it is against the policy of EE to ask multiple questions in one thread.

LeoAhmad
0
 
LVL 2

Author Closing Comment

by:auraorange
ID: 34173173
Worked perfectly

Thank you once again
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question