Where can I find a list of events in Excel? I want to write macros in VBA based on them. I already know of Worksheet_BeforeDoubleClick
, but I more or les开发者_开发知识库s just discovered that randomly/remembered it was used in Access.
Does anyone have a complete list or know where I can find one of the different events in Excel?
Here is the excel object model overview which you can use to navigate to the members of each model.
http://msdn.microsoft.com/en-us/library/wss56bz7(VS.80).aspx
You would use this to get to:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.application_members.aspx
Scroll down for events.
These are some good links to learn about Excel's events:
- Beginning VBA: Events
- Event Macros, Worksheet Events and Workbook Events
- Events in Excel VBA
Another way to find them is open the VBE (Alt+F11), click on the object's class module (such as ThisWorkbook or Sheet1), and use the drop down boxes at the top of the code panel. If, for instance, you select ThisWorkbook from left drop down, the right drop down will contain all of the events available to you.
For objects that aren't Workbook or Worksheet (Application, QueryTable, etc), create a custom class module in your project (Insert - Class Module) and type (for example)
Public WithEvents qt As QueryTable
Now 'qt' will appear in the left drop down and all of the events for a QueryTable will appear in the right one. You'll notice that the Intellisense only shows a limited number of objects when you include WithEvents. These are the only objects that have exposed events. So you can't type
Public WithEvents rng As Range
because the Range object doesn't expose any events. A little more cumbersome than James' answer, but a nice way to browse the events when you know the object and to get a list of objects with exposed events.
精彩评论