• VBA to set “Move object with text”

    Author
    Topic
    #480516

    I have a Word 2007 document with ~60 floating objects in it. I need to set the “Move object with text” option for every one of them and I’d rather not do it manually. I can’t figure out the right code for it. Can anyone help me out?

    I was thinking something like:

    For each Shape in ActiveDocument.Shapes
    Shape.RelativeVerticalPosition

    but I can’t figure it from there.

    Thanks in advance…

    Beej

    Viewing 1 reply thread
    Author
    Replies
    • #1310761

      This does seem to be specified by the ShapeRange.RelativeVerticalPosition property of the shape If you set it to wdRelativeVerticalPositionPage it stays positioned to the page. If you set it to wdRelativeVerticalPositionParagraph it moves with the text.

      I figured this out by recording macros that changed the “moves with text” box check for an existing shape, one that was set to move with the text and one that was not. The macros showed the settings for the ShapeRange property, and the only difference I could spot was in that property.

      So you loop through all the relevant shapes and set their ShapeRange.RelativeVerticalPosition to wdRelativeVerticalPositionParagraph.

      – Jessica

    • #1310763

      Weird. I just ran this code:

      Sub Fix_Santa()

      For Each Shape In ActiveDocument.Shapes

      Shape.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph

      Next Shape

      End Sub

      And it moved the objects (I had them aligned at the top of the page; they all moved back to where I had them before), but the check box isn’t checked for any of them. In fact, I can’t figure out what setting the code changed.

      Curiouser and curiouser!

    Viewing 1 reply thread
    Reply To: VBA to set “Move object with text”

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: