+ Reply to Thread
Results 1 to 7 of 7

Identifying Objects

  1. #1
    Jzz
    Guest

    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. #2
    Nick Hebb
    Guest

    Re: 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. #3
    Jzz
    Guest

    Re: 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. #4
    Andy Pope
    Guest

    Re: 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. #5
    Jzz
    Guest

    Re: 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. #6
    Nick Hebb
    Guest

    Re: 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. #7
    Jzz
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1