Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing properties to a procedure

I've got a spreadsheet that uses "traffic lights" to
indicate the health of different parts of the business.
These traffic lights are just circles drawn with the
autoshapes option, and then given background colours of
green, orange and red.

I've written a simple macro that can be assigned to a
circle that changes the colour from green to orange to red
and back to green as you click on the circle. However,
I've got a lot of circles and I don't want to write
individual macros for each - I want to be able to assign
the same macro to each one.

How can I change my macro so that it realises that the
circle I want to change is the one I've just clicked on?
The steps I would want are that you click on the circle
and macro says - ah, you've clicked on "Oval X" and then
runs the code based on this selection. My current solution
which requires me to tell the macro which circle to change
(i.e. Shapes("Oval X").Select).

Regards,

Matt




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Passing properties to a procedure

Matt,

Application.Caller will return the name of the shape that called
the macro. Therefore, you can use code like

Sub ShapeClick()
Dim SH As Shape
Set SH = Worksheets(1).Shapes(Application.Caller)
MsgBox SH.Name
End Sub

Assign this macro to all the shape objects, and SH will contain a
reference to the shape that was clicked.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Matt McQueen" wrote in message
...
I've got a spreadsheet that uses "traffic lights" to
indicate the health of different parts of the business.
These traffic lights are just circles drawn with the
autoshapes option, and then given background colours of
green, orange and red.

I've written a simple macro that can be assigned to a
circle that changes the colour from green to orange to red
and back to green as you click on the circle. However,
I've got a lot of circles and I don't want to write
individual macros for each - I want to be able to assign
the same macro to each one.

How can I change my macro so that it realises that the
circle I want to change is the one I've just clicked on?
The steps I would want are that you click on the circle
and macro says - ah, you've clicked on "Oval X" and then
runs the code based on this selection. My current solution
which requires me to tell the macro which circle to change
(i.e. Shapes("Oval X").Select).

Regards,

Matt






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
Stop a Procedure from another procedure Ayo Excel Discussion (Misc queries) 1 October 30th 08 01:42 AM
Passing a UDF as an argument to a UDF puff Excel Discussion (Misc queries) 3 February 23rd 06 09:46 PM
Passing parameter from Excel to stored procedure? hmmm... Excel Programming 1 July 25th 03 02:59 PM
Passing a Password to a VBA Procedure Orlando Magalhães Filho Excel Programming 0 July 9th 03 05:41 AM


All times are GMT +1. The time now is 02:29 PM.

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"