Results 1 to 5 of 5

Thread: Configure z-order position of shape

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Regular
    Joined
    Sep 2020
    Posts
    40
    Location
    Sir I tried below code but not getting result

    Sub replace_shape()
    Dim osld As Slide
    Dim oshp As Shape
    Dim gshp As Shape
    Dim hshp As Shape
    Dim pshp As ShapeRange
    Dim j As Long
    Dim t As Long
    Dim l As Long
    Dim h As Long
    Dim w As Long
    Dim x As Long
    Dim s As Long
    Dim TopZ As Long
    Dim TopGZ As Long
    Dim GZ  As Long
    Dim zposition As Long
    Dim finalposition As Long
    Dim GIC  As Long
    Dim GII  As Long
    Dim GIZ  As Long
    'On Error Resume Next
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    oshp.Copy
    If Err Then Exit Sub
    Set osld = ActivePresentation.Slides(1)
    For j = 1 To 2
    ' capture group/shape z-order position------------
       GIC = osld.Shapes("Group" & j).GroupItems.Count
       GZ = osld.Shapes("Group" & j).GroupItems(GIC).ZOrderPosition
      'Exit Sub
    '--------- end -------------------------------------
       Set gshp = osld.Shapes("Group" & j)
        gshp.PickupAnimation
    If gshp.Type = msoGroup Then
        gshp.Ungroup
    End If
    ' capture group items z-order position after ungroup ------------
    GIZ = osld.Shapes("Oval" & j).ZOrderPosition
    '--------- end -------------------------------------
    Set hshp = osld.Shapes("Oval" & j)
    Set pshp = osld.Shapes.Paste
    With pshp
    .Left = hshp.Left
    .Top = hshp.Top
    .Height = hshp.Height
    .Width = hshp.Width
    End With
    hshp.Delete
    With pshp
       .Name = "Oval" & j
     End With
    '-----apply z-order postion back to shape ie in Oval----------
    With osld.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1)
    TopZ = .ZOrderPosition - 1
    .Delete
    End With
    Do
    osld.Shapes("Oval" & j).ZOrder (msoBringForward)
    ' check the last groupitem not the group itself
    Loop While osld.Shapes("Oval" & j).ZOrderPosition < GIZ
    '--------- end -------------------------------------------------
    Set gshp = osld.Shapes.Range(Array("Oval" & j, "TextBoxTop" & j, "TextBoxBottom" & j, "Rectangle" & j)).Group
        gshp.ApplyAnimation
    gshp.Name = "Group" & j
     '-----apply z-order postion back to group ----------
    With osld.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1)
      TopGZ = .ZOrderPosition - 1
      .Delete
    End With
    Do
    osld.Shapes("Group" & j).ZOrder (msoBringForward)
    Loop While osld.Shapes("Group" & j).GroupItems(GIC).ZOrderPosition < GZ
    '--------- end -------------------------------------------------
    Next j
    MsgBox "Shape replace successfully!"
    End Sub
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

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