Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    16
    Thanked 0 Times in 0 Posts

    VBA to set "Move object with text"

    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

  2. #2
    Star Lounger
    Join Date
    Feb 2011
    Location
    Washington, DC
    Posts
    98
    Thanks
    8
    Thanked 6 Times in 6 Posts
    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
    Last edited by jweissmn1; 2011-12-15 at 11:13.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    Durham, North Carolina, USA
    Posts
    140
    Thanks
    5
    Thanked 1 Time in 1 Post
    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!

  4. #4
    Star Lounger
    Join Date
    Feb 2011
    Location
    Washington, DC
    Posts
    98
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Try it with ShapeRange, not Shape.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •