Share via

Change ZOrder of grouped shapes (VBA)

Anonymous
2013-04-15T21:06:44+00:00

Hi all,

I try to use the following code to group two shapes (text boxes):

Sub T2()

Dim T1  As Shape

Dim T2  As Shape

Set T1 = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 50, 250, 50)

With T1

.Name = "BoxOne"

With .TextFrame.TextRange

.Font.Color = wdColorBlue

.Text = "This is the first line of the first text box." & vbCr & "This is the second line of the first text box."

End With

End With

Set T2 = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 50, 250, 50)

With T2

.Name = "BoxTwo"

With .TextFrame.TextRange

.Font.Color = wdColorRed

.Text = " This is the first line of the second text box." & vbCr & " This is the second line of the second text box."

End With

End With

T1.ZOrder msoSendBehindText

T2.ZOrder msoBringInFrontOfText

'  group the text boxes

T1.Select

T2.Select False

Selection.ShapeRange.Group

End Sub

Basically the code is working. But I have no chance to change the ZOrder of the two shapes in a way that  the user can select the text box "BoxTwo" with the mouse. Independent of all ZOrder statements that I tried always "BoxOne" is the one that gets selected and is selectable. Of course I can change the sequence of the text boxes creation in this sample, but I have no influence of the creating sequence in reality.

I'd be very thankful for any idea!

BTW, I use the strange way of grouping the shapes together with the Select statements because that's the onliest way I could find how programmatically grouping items really works. The samples from MS don't seem to work.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2013-04-16T22:14:54+00:00

    Basically the code is working. But I have no chance to change the ZOrder of the two shapes in a way that  the user can select the text box "BoxTwo" with the mouse. Independent of all ZOrder statements that I tried always "BoxOne" is the one that gets selected and is selectable. Of course I can change the sequence of the text boxes creation in this sample, but I have no influence of the creating sequence in reality.

    I'd be very thankful for any idea!

    BTW, I use the strange way of grouping the shapes together with the Select statements because that's the onliest way I could find how programmatically grouping items really works. The samples from MS don't seem to work.

    I would guess that it has something to do with the Grouping. The grouping function keeps the items together and until they are ungrouped, it's not going to let you rearrange the order. However, you could try experimenting with the other mso properties of BringForward, SendBack, etc.

    Regarding the Grouping and having to set the Replace attribute to False is probably a shortcoming in the Word 2011 Object Model. You should send a Feedback message to MS on that. In addition you should point out that the Array function for selecting Shape ranges is not working at all.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-04-16T14:27:20+00:00

    Was this answer helpful?

    0 comments No comments