Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA code to find macros associated with command buttons in an s/s

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VBA code to find macros associated with command buttons in an s/s

A button has a name and a Caption which may be different. this code get both
name and caption.

Sub Getbutton()
For Each but In ActiveSheet.Shapes
If Left(but.Name, 13) = "CommandButton" Then
MsgBox OLEObjects(but.Name).Object.Caption
End If
Next but
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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command buttons & macros Jock W Excel Discussion (Misc queries) 3 February 21st 05 02:57 PM
MACROS & COMMAND BUTTONS Michael Excel Programming 0 June 9th 04 07:41 PM
MACROS & COMMAND BUTTONS Libby Excel Programming 0 June 7th 04 07:22 PM
MACROS & COMMAND BUTTONS Don Guillett[_4_] Excel Programming 0 June 7th 04 07:18 PM
Macros and command buttons Michael Excel Programming 2 June 6th 04 03:22 AM


All times are GMT +1. The time now is 11:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"