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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect which form button has been clicked(Excel) 1

Status
Not open for further replies.

itchyII

MIS
Apr 10, 2001
167
Hi Everyone,
I have an Excel 2000 spreadsheet. The first sheet in the workbook is kind of a 'Control Sheet'. It has numerous Excel form buttons (right on the page). There is a button for printing each report (the reports are basically other worksheets with al kinds of graphs). The code for this print is the same for all buttons except the sheet that is being printed is different. I would like to write only one sub/function that each of these buttons fires off, and in the function/sub, I would like to be able to detect which button was clicked (by either the name or the text on the button), and then I will print the appropriate worksheet. The proble is that I don't know how to detect which button was pressed!

Thanks in advance!

ItchyII
 
In each button's Click event, specify that it calls the print function with a parameter. The parameter could be the name of the sheet.

Inside the Print function, this can be used to decide which sheet to print.

Cheers
Dave

[joinedupwriting]
"whaddaya mean, 'invalid tag'?!?"
[/joinedupwriting]

[lightsaber]
 
Hi itchyII,

If your buttons are off the Forms toolbar then you can pick up the name of the button which has invoked your macro from [blue]Application.Caller[/blue] - and use this as an index into the collection.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks Tony, that was just the tip that I needed!

Excellent!

ItchyII
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top