Recording text wrapping layout options macro

R

reclusive monkey

Hello,

I would like to record a macro which will allow me to change a bunch
of settings for an inserted image. However, when I start to record the
Text Wrapping --> More Layout Options is greyed out. Is there a way
round this or is it not possible to access the Layout Options via VBA?
Thanks in advance.
 
J

Jay Freedman

Hello,

I would like to record a macro which will allow me to change a bunch
of settings for an inserted image. However, when I start to record the
Text Wrapping --> More Layout Options is greyed out. Is there a way
round this or is it not possible to access the Layout Options via VBA?
Thanks in advance.

It certainly is possible to access the options through VBA -- but not by using
the recorder. You'll have to modify the recorded macro manually (see
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm).

If the inserted image is in line with text, it will be an InlineShape object --
the recorded code will be something like

Selection.InlineShapes.AddPicture FileName:="C:\pic.jpg"

First you have to assign it to a variable, by making these changes (note the
added parentheses):

Dim myInlineShp As InlineShape
Set myInlineShp = Selection.InlineShapes.AddPicture(FileName:="C:\pic.jpg")

Then you have to convert that to a Shape object, which VBA stores in a different
object collection:

Dim myShp As Shape
Set myShp = myInlineShp.ConvertToShape

Finally you can modify the shape's .WrapFormat object, which has a property for
each of the items in the Layout Options dialog page:

With myShp.WrapFormat
.Type = wdWrapSquare
.DistanceTop = 24 ' points
' etc.
End With

If the original picture is inserted with any wrapping other than In Line With
Text, then the recorded text will use ActiveDocument.Shapes.AddPicture. You can
assign that directly to a Shape object (again using the Set keyword) and skip
the part about converting from an InlineShape.
 

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