Senin, 22 Desember 2014

Re: [ExcelVBA] Detect which shape "starts" a macro

 

This is more simple :-

    strShapeName = Application.Caller

Regards

Derek Turner +++



From: "'Tim Lewis' twlewis@reagan.com [ExcelVBA]" <ExcelVBA@yahoogroups.com>
To: ExcelVBA@yahoogroups.com
Sent: Sunday, 21 December 2014, 20:34
Subject: RE: [ExcelVBA] Detect which shape "starts" a macro

 
Hi Torstein,
 
Here is an example of identifying the name:
 
Sub IdentifyShape()
Dim strShapeName As String
strShapeName = ActiveSheet.Shapes(Application.Caller).Name
MsgBox "The shape name is " & strShapeName
End Sub
 
to base code on the name would be:
If strShapeName = "Shape1" Then
                'do stuff
End If
 
If you need to know the names of all shapes, use this:
Sub IdentifyShapes()
Dim strShapeName As String
'Sheets("Sheet1").Select
For Each Shape In ActiveSheet.Shapes
 
    Shape.Select  ' This shows which shape is the current shape
    strShapeName = Shape.Name
 
'If you need to rename a shape to a more meaningful name, use this
   ' If Shape.Name = "Shape1" Then
       ' Shape.Name = "GetNewData"
   'End If
Next
End Sub
 
 
 
I hope that you have a great Christmas and New Year.
 
Tim
 
 
 
From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com]
Sent: Sunday, December 21, 2014 9:26 AM
To: ExcelVBA@yahoogroups.com
Subject: [ExcelVBA] Detect which shape "starts" a macro
 
 
In a worksheet there are several shapes.
 
They are all assigned to the same macro.
 
Is it possible in the macro to detect which skape that was "clicked on" to start the macro?
 
I wish the macro to do different tasks dependent on which shape that started it!
 
Is there a sort of activeShape object?
 
Regards and Merry Christmas to all of you Excelers!
 
Torstein Johnsen


__._,_.___

Posted by: Derek Turner <g4swy@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Posting Komentar