0
votes

I want to use a word macro to set the position of the shapes in the document to book layout (see screenshot). But I can't find any reference which member I need to set for this (probably because my word is in german and this is called differently in the macro).

Can anyone tell me how to set the horizontal layout of a shape to book layout in vba?

Screenshot from word

[update] The following did the trick:

Shape.Left = -999994
Shape.LeftRelative = -999999
Shape.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
1
Have you tried using the Marco recorder (Bottom left in newer versions of Word)? Oddly my copy crashes each time I OK the new position.David Rushton
When I use the macro recorder I'm not able to edit the properties of Images :/Sam
Now I managed to enter the dialog in the macro recorder, made the changes, but in the macro there is nothing recorded for this. So I still got no clue how to set it.Sam

1 Answers

2
votes

In the most recent versions of Word the macro recorder gives no help for graphical objects. The next best thing you can do is to look at the properties available for the object in the Object Browser (F2).

If a graphical object has "text wrap" formatting then it belongs to the Shapes collection, so the list you need to look up is that of the Shape object.

In there you'll find the property RelativeHorizontalPosition, which takes a member of the WdRelativeHorizontalPosition enumeration. Looking at that list there are a number of options, none of which has "book" in it.

So the next step is to insert and format a Shape with the desired positioning. Then in the Immediate Window (Ctrl+G) you can type:

?ActiveDocument.Shapes(1).RelativeHorizontalPosition

Then press Enter. This will print a number that corresponds to the list of Enumeration members.

You can also test the effect of the various members by assigning them in the Immediate Window:

ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionOuterMarginArea

Press Enter.

What you'll see is that there is not an enumeration member for every option in the dialog box. And that various positioning options in the dialog box correspond to a single enumeration member.

For your specific question, wdRelativeHorizontalPositionInnerMarginArea corresponds to the dialog box option you indicate.

ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionInnerMarginArea 

Besides the above, you need to use the LeftRelative and Left properties, as well. Take a look at those settings in the Immediate Window after using the dialog box and play with them, putting the image on odd/even pages.If it disappears - it's off visible portion of the page, which you can see in Reading View. In a nutshell, you need the NEGATIVE numbers to lock the image to the margin or page side. Positive numbers position it absolutely.