PC Review


Reply
Thread Tools Rate Thread

Change order of Shapes with a click

 
 
John Michl
Guest
Posts: n/a
 
      21st Nov 2005
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

 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      21st Nov 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Leith Ross
Guest
Posts: n/a
 
      21st Nov 2005

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

 
Reply With Quote
 
John Michl
Guest
Posts: n/a
 
      21st Nov 2005
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change display order of shapes within a Smart Art shape? =?Utf-8?B?ZHN3dGFu?= Microsoft Powerpoint 0 22nd Sep 2006 09:43 PM
Change order of right click menu in Windows Explorer Tim Windows XP Customization 9 19th Jan 2006 01:31 AM
change order of right click commands David Windows XP Customization 9 26th Nov 2004 01:19 AM
Using the mouse to click and drag records to change their order John Baker Microsoft Access Forms 4 18th Sep 2003 07:02 PM
Using the mouse to click and drag records to change their order John Baker Microsoft Access Form Coding 4 18th Sep 2003 07:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:53 PM.