Senin, 22 Desember 2014

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

 

Tim and Derek! Thank you for your suggestions, I'll try to check it out in a day or four. But as you know there are several family days coming soon, not much time for VBA.

And then I'll try to explain another approach that I found too. 

Torstein



Den 21. des. 2014 kl. 21.34 skrev 'Tim Lewis' twlewis@reagan.com [ExcelVBA] <ExcelVBA@yahoogroups.com>:

 

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: Torstein Johnsen <sejohnse@yahoo.no>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
----------------------------------
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