View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VBA code to find macros associated with command buttons in an s/s

First, if you really meant commandbuttons (those are from the control toolbox
toolbar), then you don't assign the macro.

If you doubleclick on one of these commandbuttons while in design mode, you'll
see that it has an event associated with it:

Option Explicit
Private Sub CommandButton1_Click()
End Sub

If you meant buttons from the Forms toolbar, you could use code like:

Option Explicit
Sub testme()

Dim myBTN As Button

For Each myBTN In ActiveSheet.Buttons
If myBTN.OnAction = "" Then
MsgBox "No macro assigned to " & myBTN.Name
Else
MsgBox myBTN.OnAction & vbLf & "is assigned to " & myBTN.Name
End If
Next myBTN

End Sub

wrote:

Given a sheet containing many command buttons, how can I find the
macros/subroutines associated with those buttons? (i want to do it in
vba code, rather than right click each button and select "assign
macro") Thanks a lot.


--

Dave Peterson