+ Reply to Thread
Results 1 to 7 of 7

how to get the name of the shape clicked

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    how to get the name of the shape clicked

    Hi,

    Is there any way that I can get the name of the shape i just clicked to call a procedure?

    I have 35 shapes in my Worksheet.
    Each shape has a different name. Each shape has a macro procedure assigned, wich do almost the same procedure (with just small differences, depending on from wich shape the macro was called).

    I want to make just one macro procedure and catch from wich shape the macro was called.
    Last edited by Wizz; 01-21-2009 at 05:15 PM.

  2. #2
    Registered User
    Join Date
    03-16-2004
    Location
    UK
    MS-Off Ver
    2003
    Posts
    85
    I don't think there is a response in application events when you click shape.
    You could try this. Create the shapes and assign each to a macro and then have a variable in you main subroutine. For example...

    Sub Rectangle3_Click()  'Assigned to shape 'Rectangle 3'
    N = "Rectangle3" Call myMacro("Rectangle3")
    End Sub Sub Rectangle4_Click() ' 'Assigned to shape 'Rectangle 4'
    N = "Rectangle4" Call myMacro("Rectangle4")
    End Sub Sub myMacro(clck)
    MsgBox "You clicked, " & clck
    End Sub
    Hope that helps.
    Phil

  3. #3
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186
    Hi Phil!
    Thats what I am currently doing. But I wanted a better solution; in wich I do not have to write 35 Subs to call a procedure.

    But I thank you very much for your time and efford.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try adapting this code that uses Application.Caller

    
    Option Explicit
    
    Sub whoClicked()
    ActiveSheet.Shapes(Application.Caller).Select
    MsgBox Selection.Name
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Exactly what I needed!

    Thank you very much!

  6. #6
    Registered User
    Join Date
    09-22-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: how to get the name of the shape clicked

    That was Awesome!

  7. #7
    Registered User
    Join Date
    11-07-2013
    Location
    Mexico
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: how to get the name of the shape clicked

    Thank you very much! I spent a lot of time looking for that! Thanks! Thanks! Thanks!

+ 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