Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change series plotting order without changing legend order? PatrickM Charts and Charting in Excel 6 December 2nd 09 07:43 PM
How to change shapes for Cell Comments Jan T.[_3_] Excel Discussion (Misc queries) 3 December 15th 08 11:10 PM
How to change syperlink from single click to double click syperlinker Excel Worksheet Functions 0 June 13th 08 05:01 PM
Selection order problem with code for shapes connection [email protected] Excel Programming 2 August 12th 05 02:03 PM
trapping click events on shapes Matt I Excel Programming 3 August 15th 03 08:17 PM


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"