Hey people,

I am novice to word VBA programming.

I have a word document and it contains, pictures, charts and canvas
(powerpoint slides).
Currently, I use the following code to center align the pictures and
charts.

Sub test()
Dim dc As Document
Dim ilShp As InlineShape

Set dc = ActiveDocument

For Each ilShp In dc.InlineShapes
If Not ilShp.Type = wdInlineShapeOLEControlObject Then
ilShp.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End If
Next

End Sub

I trying to write macros to:
1. Center align a canvas
2. Strecth/resize a picture to fit the width of the page while
mainitaing the aspect ratio.

Please let me know the macro for those.

I would really appreciate any help. Thank You.

Re: Macro to resize and center align pictures, charts, canvas in MS by ucanalways

ucanalways
Mon Nov 26 16:44:36 PST 2007

On Nov 26, 10:43 am, ucanalw...@gmail.com wrote:
> Hey people,
>
> I am novice to word VBA programming.
>
> I have a word document and it contains, pictures, charts and canvas
> (powerpoint slides).
> Currently, I use the following code to center align the pictures and
> charts.
>
> Sub test()
> Dim dc As Document
> Dim ilShp As InlineShape
>
> Set dc = ActiveDocument
>
> For Each ilShp In dc.InlineShapes
> If Not ilShp.Type = wdInlineShapeOLEControlObject Then
> ilShp.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
> End If
> Next
>
> End Sub
>
> I trying to write macros to:
> 1. Center align a canvas
> 2. Strecth/resize a picture to fit the width of the page while
> mainitaing the aspect ratio.
>
> Please let me know the macro for those.
>
> I would really appreciate any help. Thank You.

Guys, can anyone please help me to solve my macro problem? Thanks

Re: Macro to resize and center align pictures, charts, canvas in MS by fumei

fumei
Tue Nov 27 10:53:42 PST 2007

Regarding the centering, the best way would be to make a style for your
images. This is a good idea generally. All my images use an image paragraph
style.

So say you have a style - MyImageCenter - and it is centered, or whatever.

Sub test()
Dim dc As Document
Dim ilShp As InlineShape

Set dc = ActiveDocument

For Each ilShp In dc.InlineShapes
If Not ilShp.Type = wdInlineShapeOLEControlObject Then
ilShp.Range.Style = "MyImageCenter"
End If
Next
End Sub

This applies the cenetring style. Done.

As for the resizing...this can get tricky, but can be done.

The EASIEST way, and if the images are all the same size to start with, is to
manually do the resizing and note the Scale percentage change. So say you
resized it, and the Scale change is 150, that it, it is 150% bigger than the
original. Now you could use:

Sub test()
Dim dc As Document
Dim ilShp As InlineShape

Set dc = ActiveDocument

For Each ilShp In dc.InlineShapes
If Not ilShp.Type = wdInlineShapeOLEControlObject Then
With ilShp
.LockAspectRatio = msoTrue
.ScaleWidth = 150
End With
ilShp.Range.Style = "MyImageCenter"
End If
Next
End Sub

Still using the style to do the centering, but scaling each up 150%.

--
Message posted via http://www.officekb.com