Consulting

Results 1 to 7 of 7

Thread: positioned second from front in powerpoint vba

  1. #1
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location

    positioned second from front in powerpoint vba

    Sir,

    I have 40 different shapes & one group(say group1). In selection pane position of the group1 is 12th from the top. Now I want to position group1 second from top.
    Is it possible with vba code?
    I found ZOrderPosition property & Zorder msoBringForward but not configure out. please help.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    There is no command to move to a specific zorderposition

    In your particular case you could do it in 2 steps

    Sub moveIT()
    Dim osld As Slide
    'change to actual slide number
    Set osld = ActivePresentation.Slides(1)
    osld.Shapes("Group1").ZOrder (msoBringToFront)
    osld.Shapes("Group1").ZOrder (msoSendBackward)
    End Sub
    More generally you would have to use a loop

    Sub moveIT2()
    Dim osld As Slide
    Set osld = ActivePresentation.Slides(1)
    Do
    osld.Shapes("Group1").ZOrder (msoBringForward)
    Loop While osld.Shapes("Group1").ZOrderPosition < osld.Shapes.Count - 1
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    Sir thanks for helping me.
    first code works perfectly.
    But when I run the second code(loop) it goes only one step forward. I attach a presentation where I want to position Group 17 in second from top but it goes only one step forward. Please see presentation example11.pptm
    Attached Files Attached Files

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I see that too. Groups can do strange things when you play with the zordrposition. use the code that works!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    Thanks Sir

    I found a code in https://docs.microsoft.com/ to places the shape second from the back & its working with group also.
    But I need exactly opposite to that.

    Sub move()
    Dim osld As Slide
    'change to actual slide number
    Set osld = ActivePresentation.Slides(1)
    With osld.Shapes("Group 17")
       While .ZOrderPosition > 2
             .ZOrder msoSendBackward
       Wend
    
    
    End With
    
    End Sub


    I manipulate(msoSendForward) with this code but not get desire result.

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It is pretty difficult to do especially with Groups.

    MSFT handle group0s in a verey strange way. A group with say three mshapes inside is treated as FOUR shapes in some places but only 1 in others.

    also zorderposition 1 is the back but you have to calculate what the front would be - bearing in mind how group are counted this is not simple

    This should work but make sure you work on a copy as it might crash.

    Sub moveIT2()
    Dim osld As Slide
    Dim TopZ As Long
    Dim GI  As Long
    Set osld = ActivePresentation.Slides(1)
    GI = osld.Shapes("Group 17").GroupItems.Count
    ' add a shape and check the zorder for the new front then delete it
    With osld.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1)
    TopZ = .ZOrderPosition - 1
    .Delete
    End With
    Do
    osld.Shapes("Group 17").ZOrder (msoBringForward)
    ' check the last groupitem not the group itself
    Loop While osld.Shapes("Group 17").GroupItems(GI).ZOrderPosition < TopZ - 1
    End Sub
    Last edited by John Wilson; 06-28-2021 at 07:50 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    So many Thanks Sir,

    Its perfectly working now. I have no words to appreciate you. You gave valuable suggestion whenever I struck. May god bless you.

Posting Permissions

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