Switch all graphics in a document from "floating" to "inline-centered"

A

andreas

I got a long document with a lot of "floating" graphics which should
be formatted to be "inline" with text and centered.
I tried to write the macro using the macro recorder first but could
not access the necessary graphic properties.

How can I reformat All ! floating graphics from "floating" to "inline-
centered" with one macro?

Help is appreciated. Thank you very much in advance.

Regards, Andreas
 
G

Greg Maxey

Andreas,

Very limited testing ;-)

Sub ScratchMacro()
Dim oShape As Shape
For Each oShape In ActiveDocument.Shapes
oShape.WrapFormat.Type = wdWrapInline
oShape.Anchor.Paragraphs(1).Alignment = wdAlignParagraphCenter
Next
End Sub
 
H

Helmut Weber

Hi Andreas,

Sub Test405()
Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
oShp.ConvertToInlineShape
Next
End Sub

If I select an inlineshape and look at "format picture", "layout",
"wrapping style", then all options in "horizontal alignment"
are greyed out. Understandably, as centered and inline with text are,
as far as I see, not compatible.

There is a horizontallineformat property of an inlineshape,
but this seems to be somewhat misleading.
At least I coundn't get it to do anything sensible.

However, if there is no text in the paragraph,
which holds the inlineshape, then centering that paragraph
might be what you want.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

andreas

Andreas,

Very limited testing ;-)

Sub ScratchMacro()
Dim oShape As Shape
For Each oShape In ActiveDocument.Shapes
oShape.WrapFormat.Type = wdWrapInline
oShape.Anchor.Paragraphs(1).Alignment = wdAlignParagraphCenter
Next
End Sub






- Zitierten Text anzeigen -

Greg,
although your code looks logical from my point of view, it is not
working, i.e. graphics are not converted from floating to inline. But
as you said, it has not been tested.

The one below from Helmut is running fine. Thanks anyway Greg.

Regards, Andreas
 
G

Greg Maxey

Andreas,

I got hung up "with all graphics." The problem
with .ConverttoInlineShape is that it would throw an error if it
encountered a drawing shape. Here is a slight modification to
Helmut's code that you might prefer:

Sub Test405()
Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
On Error GoTo Err_Handler
oShp.ConvertToInlineShape
ReEnter:
Next oShp
Exit Sub
Err_Handler:
If MsgBox("The current shape not of the type picture, OLE object or
ActiveX" _
& " control. Do you want to set the wrap format of this shape"
_
& " to inline?", vbYesNo, "Decision Point") = vbYes Then
oShp.WrapFormat.Type = wdWrapInline
oShp.Anchor.Paragraphs(1).Alignment = wdAlignParagraphCenter
Resume ReEnter
End If
End Sub
 
A

andreas

Hi Andreas,

Sub Test405()
Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
oShp.ConvertToInlineShape
Next
End Sub

If I select an inlineshape and look at "format picture", "layout",
"wrapping style", then all options in "horizontal alignment"
are greyed out. Understandably, as centered and inline with text are,
as far as I see, not compatible.

There is a horizontallineformat property of an inlineshape,
but this seems to be somewhat misleading.
At least I coundn't get it to do anything sensible.

However, if there is no text in the paragraph,
which holds the inlineshape, then centering that paragraph
might be what you want.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Thank you Helmut for your assistance, It is working

Regards, Andreas
 

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