+ Reply to Thread
Results 1 to 4 of 4

Change order of Shapes with a click

  1. #1
    John Michl
    Guest

    Change order of Shapes with a click

    I have eight shapes on a sheet. I'd like to be able to click on a
    shape and if its zorder is 1, bring it to the front. If not, send it
    to the back. The following code does this but I must name each shape
    and have a chunck of code for each shape.

    How can I genericize this so that whatever shape is clicked, it will
    change order?

    Sub ToggleOrder()

    If ActiveSheet.Shapes("NameOfShape").ZOrderPosition <= 1 Then
    ActiveSheet.Shapes("NameOfShape").ZOrder msoBringToFront
    Else
    ActiveSheet.Shapes("NameOfShape").ZOrder msoSendToBack
    End If

    End Sub

    - John


  2. #2
    Tom Ogilvy
    Guest

    Re: Change order of Shapes with a click

    Sub ToggleOrder()
    sName = Application.Caller
    If ActiveSheet.Shapes(sName).ZOrderPosition <= 1 Then
    ActiveSheet.Shapes(sName).ZOrder msoBringToFront
    Else
    ActiveSheet.Shapes(sName).ZOrder msoSendToBack
    End If

    End Sub

    --
    Regards,
    Tom Ogilvy



    "John Michl" <[email protected]> wrote in message
    news:[email protected]...
    > I have eight shapes on a sheet. I'd like to be able to click on a
    > shape and if its zorder is 1, bring it to the front. If not, send it
    > to the back. The following code does this but I must name each shape
    > and have a chunck of code for each shape.
    >
    > How can I genericize this so that whatever shape is clicked, it will
    > change order?
    >
    > Sub ToggleOrder()
    >
    > If ActiveSheet.Shapes("NameOfShape").ZOrderPosition <= 1 Then
    > ActiveSheet.Shapes("NameOfShape").ZOrder msoBringToFront
    > Else
    > ActiveSheet.Shapes("NameOfShape").ZOrder msoSendToBack
    > End If
    >
    > End Sub
    >
    > - John
    >




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello John,

    The Sheets are a collection object. You can step through all the items in any collection object by using the For Each ... Next loop.

    Sub ToggleOrder()

    Dim Shp
    For Each Shp In ActiveSheet.Shapes
    If Shp.ZOrderPosition < = 1 Then
    Shp.ZOrder msoBringToFront
    Else
    Shp.ZOrder msoSendToBack
    End If
    Next Shp

    End Sub

    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 11-21-2005 at 05:49 PM.

  4. #4
    John Michl
    Guest

    Re: Change order of Shapes with a click

    Thanks, Tom. Exactly what I was looking for. I'm not familiary with
    Application.Caller so I'll look that one up in the online reference.

    - John


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1