Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Keeping Boxes from Moving

    Hello,

    I am writing a macro that cycles through the text boxes in a file. It ungroups them, does some processing on each and then regroups. I would like the boxes to not be moved relative to the margins by this operation.

    Currently, the position of the grouped boxes is set to column and paragraph. Even when I change this to margin-margin with:

    ActiveDocument.Shapes(BoxNo).Select
    Selection.ShapeRange.RelativeHorizontalPosition = _
    wdRelativeHorizontalPositionMargin
    Selection.ShapeRange.RelativeVerticalPosition = _
    wdRelativeVerticalPositionMargin
    Selection.ShapeRange.LockAnchor = True

    before ungrouping and then on each box before processing, they hop around!

    Thanks for any help,

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Keeping Boxes from Moving

    Hi Ed,

    It seems your post kind of got lost in the shuffle.[img]/w3timages/icons/crazy.gif[/img]

    Too late to look at this tonight but just a quick question: couldn't you somehow first capture the information regarding horizontal and vertical position of the text boxes, store these in variables, and then when you've finished doing the ungroup/regroup etc., reapply the original horiz/vert settings?

    Gary

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keeping Boxes from Moving

    I have since verified that changing the anchoring from "paragraph" to "page margin" in a macro does not get Word to recalculate the position numbers, so the box generally moves.

    When I display the Format-Object-Position dialog box and make the same change, Word does recalculate the position values. Is there any way to simulate that process more generically than the macro recorder does (it simply puts in the new position values explicitly)?

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Keeping Boxes from Moving

    <P ID="edit"><FONT SIZE=-1>Edited by Gary Frieder on 01/02/18 11:03.</FONT></P>Hi Ed,

    I wouldn't be worrying so much about the location of the anchors, as I would about setting the group object's location to absolute to page, and capturing the location into variables so that it can be restored later.

    The following basic code example illustrates how to do this (this was done in Word 2000, hopefully it is the same in Word 97):

    <pre>Sub RestoreGroupLocation()
    '
    Dim sngLeft As Single
    Dim sngTop As Single
    '
    ActiveDocument.Shapes("Group 5").Select
    Selection.ShapeRange.RelativeHorizontalPosition = _
    wdRelativeHorizontalPositionPage
    Selection.ShapeRange.RelativeVerticalPosition = _
    wdRelativeVerticalPositionPage
    '
    sngLeft = PointsToInches(Selection.ShapeRange.Left)
    sngTop = PointsToInches(Selection.ShapeRange.Top)
    '
    'These two lines temporarily move the group for demo purposes:
    Selection.ShapeRange.Left = InchesToPoints(sngLeft + 1)
    Selection.ShapeRange.Top = InchesToPoints(sngTop + 1)
    '
    MsgBox "Group should appear to have moved; click OK to restore position"
    '
    'these two lines restore the original group location:
    Selection.ShapeRange.Left = InchesToPoints(sngLeft)
    Selection.ShapeRange.Top = InchesToPoints(sngTop)

    End Sub
    </pre>

    (If I were using this code I'd set "Selection.ShapeRange" to a variable, but have left this code example as is for maximum clarity.)

    Hope this helps - let me know.
    Gary

  5. #5
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keeping Boxes from Moving

    No, this doesnt seem to do it. This statement is the one that moves the box:

    Selection.ShapeRange.RelativeHorizontalPosition = _
    wdRelativeHorizontalPositionPage

    because, unlike using the menu in interactive mode, the numeric values are not recalculated.



    Is isnt there a way to "access" the menu you get with Format-Object-Position from a macro...Maybe a WordBasic command...?
    Selection.ShapeRange.RelativeVerticalPosition = _
    wdRelativeVerticalPositionPage

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Keeping Boxes from Moving

    Hi Ed,

    OK, I think we're starting from two different places.
    In my test file I've been starting with text boxes that are defined as having an absolute position to page to begin with.
    So the statement that's moving your boxes, doesn't cause mine to move.

    Could you possibly post a couple of screen shots of this dialog, one before you change any of the settings, and one that shows what it looks like after you change the settings to what you want.

    This would make it much easier to understand how it's initially set up, and what it needs to be changed to.

    Gary

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keeping Boxes from Moving

    Here is a new wrinkle: when a group is broken up and then regrouped, the relativity of its position is sometimes not the same as it was before ungrouping! I have observed this with a group anchored relative to the margins, consisting of items that were, when ungrouped, set to be relative to columns. When regrouped (without any changes being made to anything except for the ungrouping and regrouping), the group took on the paragraph-relative anchoring of the contained items AND THE GROUP MOVED.

    This still does not solve the problem of how to deliberately change the anchoring in a macro without moving the group, but it is of certain interest.

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Keeping Boxes from Moving

    "Relative to columns" - ayy! - hadn't even thought of that one!

    There are an awful lot of graphics formatting parameters in your document. And as we've seen, the tools for handling these from code are not the most robust.

    Would you be willing to send me (to my private e-mail) a small representative sample of your document? - it will be much easier to dig around with the actual file at hand. And then if we find any useful solutions, they can be posted back here.

    Gary

  9. #9
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keeping Boxes from Moving

    I'm still working on this one!! It seems to be necessary to recalculate the position arithmetically in VBA.

    What I need to know now is how to return the TextColumn number (index) of the current selection.

    Since I dont see any "Left" attribute for TextColumns, I presume I will have to run through all the columns to the left of the current column summing their widths and the distance to the next column.

Posting Permissions

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