ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change order of Shapes with a click (https://www.excelbanter.com/excel-programming/346197-change-order-shapes-click.html)

John Michl

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


Tom Ogilvy

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" wrote in message
oups.com...
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




Leith Ross[_296_]

Change order of Shapes with a click
 

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 Sht
For Each Sht In ActiveSheet.Shapes
If Sht.ZOrderPosition < = 1 Then
Sht.ZOrder msoBringToFront
Else
Sht.ZOrder msoSendToBack
End If
Next Sht

End Sub

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=486993


John Michl

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



All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com