use button name/caption in macro

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,056
Office Version
  1. 365
Platform
  1. Windows
hi all, i can't seem to find anything on passing the name or caption of a form control button into a macro. I am setting up a divisional report that uses the same base data. Users are to select the button with their division name on it, and this will then export the filtered contents to a new workbook. Is there a better way of doing this?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
hi all, i can't seem to find anything on passing the name or caption of a form control button into a macro. I am setting up a divisional report that uses the same base data. Users are to select the button with their division name on it, and this will then export the filtered contents to a new workbook. Is there a better way of doing this?

Hi,
to do what you want try

Code:
Sub Button1_Click()
    MyMacro Sheet1.Buttons(1).Caption
End Sub




Sub MyMacro(ByVal Caption As String)
    MsgBox Caption
End Sub

If there are not too many users then your button approach probably ok but alternative approaches would be to populate either a combobox or listbox with users names or if your users open the workbook on a corporate network then maybe use their network username to run the reports automatically.

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top