Re-size specific images in a doc

D

Delia

I'm trying to write a macro that would search through all
the images in a document, check if they have a specific
width (> than 6", let's say), and re-size them to a width
of 6", while the height changes proportionally.

In other words, fix the figures that spill over the page
margins. I also have other figures in the document (that
have a size<6") that I don't want to touch.

Can this be made? Thanks for any help.
 
D

Doug Robbins - Word MVP

Hi Delia,

Here's a bit of code from one of my projects that should help you:

'Adjust size of logo to match avalable space
oheight =
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1).Height
owidth =
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1).Width
If oheight < InchesToPoints(2) Then
With
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1)
.Height = InchesToPoints(2)
.Width = owidth * InchesToPoints(2) / oheight
End With
End If
oheight =
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1).Height
owidth =
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1).Width
If owidth > InchesToPoints(2.85) Then
With
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1)
.Width = InchesToPoints(2.85)
.Height = oheight * InchesToPoints(2.85) / owidth
End With
End If


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Delia

Thanks, Doug.

How can I tell the macro to apply the procedure to the
opened document instead of actually specifying the
document name? ActiveDocument does not work :(.

I want to be able to run this macro from a document,
before performing other tasks, rather than on a document
in the background.

Thanks again.
 
D

Doug Robbins - Word MVP

Hi Delia

Dim myDoc as Document
Set myDoc = ActiveDocument

then use the rest of the code.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Delia

Hi Doug and thanks. Sorry to bother you again.

I had already done that, but when running the macro, it
stops at the first line (oheight=...) with an error (Run-
time error 5491 "The requested member of the collection
does not exist.")

I must be doing something wrong...
 
D

Doug Robbins - Word MVP

Hi Delia,

All of the following needs to be one line of code

oheight =
myDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
1).Range.InlineShapes(1).Height

and it assumes that the image is in the first cell on thte first row of the
first table in the header. If that is not where it is, you will have to
modify the code so that it refers to your image location.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top