问题描述:

I had a wild idea on a project I was working on that would make things a lot easier and I was wondering if it was even possible. I have a series of tables next to each other. say dimension 5x100. Each Table has buttons that will perform operations on that specific section of data. Each button will activate the same macro when pressed and it is up to that macro to figure out which button was pressed.

My thought: wouldn't it be slick if I made a class including all the buttons and operations and each table was an instantiation of that class? Meaning each class would have the event handlers for all the buttons in that particular table. That way there would be no guess work for finding the data and which button was pressed because they would each have their own method and each have an associated range with it. very clean and functional.

Is this even possible? I tried to create a class module but there were not button objects available in the drop down menus. Has anyone done something like this before?

Thanks in advance! Hope the post wasn't too lengthy

网友答案:

You are over thinking it.

From your comment Each button will activate the same macro when pressed I take it you are using Form Controls (rather than ActiveX Control's).

Given that, use

ButtonName = Application.Caller

in your common macro. This will give you the name of the button that called your macro.

相关阅读:
Top