Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all!
I'm programming in Excel as a hobby, and I made a macro which draws several objects. These objects represent loaded cargo on the ship I'm sailing. When I want to change the place of these objects, I have to start a seperate macro. I can do that by clicking on the object itself, but how can I let the macro know on which object I'm clicking? (the objects all have a name such as object1, object2 and so on) Better still would it be to be able to shift the objects by mouse, but then how does the Macro know which object I'm shifting and where to? I hope this explanation was clear enough, and that someone has a solution. Greets, Jzz |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Assuming you assigned a macro via the shapes' OnAction properties, you
could have the macro pop open a user form with a list box populated with all the shapes. Select the shape and click OK, then continue on with the rest of the macro. I think the big problem is how to identify each shape. Before doing the above, you could write a little macro to go through and give the shapes meaningful names: Dim shp As Shape For Each shp In ActiveSheet.Shapes shp.Select shp.Name = InputBox("Enter shape name:") Next Set shp = Nothing Then you could use the shapes names to populate the list box I spoke of above. Hopefully, someone here comes up with a better solution because the first part seems really kludgy. But if not, I hope that helps. Nick Hebb BreezeTree Software http://www.breezetree.com |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Nick,
Thanks for your prompt reply, but this was not really what I was looking for. The shapes all have meaningfull names, but the big point is how to let the macro know on which of the shapes I'm clicking. The listbox is already some advantage, but not really nessesary as all the objects have numbers written on them. Jzz |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
If the macro is assigned to a shape then MsgBox Application.Caller will display the shapes name. Cheers Andy Nick Hebb wrote: Assuming you assigned a macro via the shapes' OnAction properties, you could have the macro pop open a user form with a list box populated with all the shapes. Select the shape and click OK, then continue on with the rest of the macro. I think the big problem is how to identify each shape. Before doing the above, you could write a little macro to go through and give the shapes meaningful names: Dim shp As Shape For Each shp In ActiveSheet.Shapes shp.Select shp.Name = InputBox("Enter shape name:") Next Set shp = Nothing Then you could use the shapes names to populate the list box I spoke of above. Hopefully, someone here comes up with a better solution because the first part seems really kludgy. But if not, I hope that helps. Nick Hebb BreezeTree Software http://www.breezetree.com -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Thanks for the reply, but this does not display the shapes name, simply the caller of the macro. This is always "object", whether the name of the object is 'object', 'trailer' or 'whatever' does not matter, so this is not the solution either, sorry. Jzz |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Andy, that's pretty sweet. I didn't know about Application.Caller.
Jzz, this works in the OnAction macro: Dim shp As Shape Set shp = ActiveSheet.Shapes(Application.Caller) MsgBox shp.Name shp.Left = shp.Left + 100 ' just for fun Set shp = Nothing Nick Hebb BreezeTree Software http://www.breezetree.com |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, yes I worked it out already, the problem was that the shape was
part of a group, and application.caller gives the name of the shapes seperately; not of the group. This caused a little confusion. Many thanks! Jzz |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Identifying | Excel Discussion (Misc queries) | |||
Identifying Top row | Excel Programming | |||
Dynamically Assign Objects to Form Objects. | Excel Programming | |||
Identifying a value | Excel Programming | |||
Unable to remove Sheet objects in the Microsoft Excel Objects | Excel Programming |