Resizing images to margins automatically

S

Sam Santiago

I have an application that is generated a Word document with many images. I have to manually go through and resize the images to fit on a single page. Is there a quick way to automatically size images to the set margins?

Thanks,

Sam
 
D

DA

Hi Sam

You'll have to use a VBA macro to resize all your images.
Here's a sample routine, which will resize all your
images to fit inside of the page margins.

'------------------------
Sub ImageResize()
Dim ishp As InlineShape
Dim lngPercentChange As Long
Dim lngPageWidth As Long

With ActiveDocument
'Find width inside margins
lngPageWidth = .PageSetup.PageWidth - _
.PageSetup.LeftMargin - .PageSetup.RightMargin

'Resize each image to fit inside margins
For Each ishp In .InlineShapes
ishp.Reset
If ishp.Width > lngPageWidth Then
lngPercentChange = 100 * (lngPageWidth / ishp.Width)
ishp.ScaleHeight = lngPercentChange
ishp.ScaleWidth = lngPercentChange
End If
Next ishp
End With
End Sub
'---------------------

Hope that helps,
Dennis
-----Original Message-----
I have an application that is generated a Word document
with many images. I have to manually go through and
resize the images to fit on a single page. Is there a
quick way to automatically size images to the set margins?
 

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