Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying name of Drawing object linked to a Macro

Status
Not open for further replies.

ajcarr

Technical User
Oct 1, 2002
69
GB
Is it possible to identify the name of a Drawing Object which has a macro assigned to it from within that macro when the macro is invoked?
 
HI,

This might work...
Code:
Sub test()
    For Each obj In ActiveSheet.DrawingObjects
        If obj.OnAction = "Book1!Macro1" Then
            MsgBox "YES"
        End If
    Next
End Sub
Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
Skip, that wasn't exactly what I was looking for but it did prove very useful. I got the answer from Combo as part of another thread that Application.Caller will give you the name of the object calling the macro.

However, I used your suggestion to produce the following bit of code which lists all the Objects and associated actions in a worksheet (there are several hundred in one of mine!)

Sub ActionList()
Dim line As Integer, obj As Object, CurrentSheet As String, ActionSheet As String
CurrentSheet = ActiveSheet.Name
Worksheets.Add
ActiveSheet.Name = CurrentSheet + " Actions"
ActionSheet = ActiveSheet.Name
Worksheets(CurrentSheet).Activate
With Worksheets(ActionSheet)
.Cells(1, 1) = "List of Actions for "
.Cells(1, 2) = CurrentSheet
line = 3
For Each obj In ActiveSheet.DrawingObjects
.Cells(line, 1) = obj.Name
.Cells(line, 2) = obj.OnAction
line = line + 1
Next
Range(.Columns(1), .Columns(2)).AutoFit
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top