Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jzz Jzz is offline
external usenet poster
 
Posts: 20
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
Jzz Jzz is offline
external usenet poster
 
Posts: 20
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
Jzz Jzz is offline
external usenet poster
 
Posts: 20
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Identifying Objects

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   Report Post  
Posted to microsoft.public.excel.programming
Jzz Jzz is offline
external usenet poster
 
Posts: 20
Default Identifying Objects

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
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
Identifying famdamly Excel Discussion (Misc queries) 2 February 26th 06 06:44 AM
Identifying Top row teresa Excel Programming 4 January 13th 05 06:27 AM
Dynamically Assign Objects to Form Objects. The Vision Thing Excel Programming 2 December 11th 04 04:02 PM
Identifying a value jtrevill[_4_] Excel Programming 1 November 18th 04 05:56 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM


All times are GMT +1. The time now is 08:46 PM.

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

About Us

"It's about Microsoft Excel"