Capturing CommandBar Events in VB Add-Ins DC

This code sample shows how to capture all the events from your command-bars in a Visual Basic Add-In using only one declared event handler.

Local Companies

Capital Management Consulting,
(202) 527-2022
5411 13th St., NW
Washington, DC
Sophisticated Technologies, Inc.
(301) 731-1015
3311 Grayvine Lane
Washington, DC
Peyton McCall, Inc.
(202) 327-4902
7504 Alaska Ave
Washington, DC
Dantech Corporation Inc.
(888) 868-9015
1700 Verbena St., NW
Washington, DC
The Myta Corporation
(301) 468-7740
6901 Barrett Lane
Bethesda, DC
Symbiont, Inc.
(202) 887-6800
1320 Fenwick Lane
Silver Spring, DC
Enlightened, Inc.
(202) 783-4655
666 11th St., NW
Washington, DC
Evergreen Computer Services, Inc
(301) 758-2986
12421 Alamanco Way
Washington, DC
The Carrington Group, Inc
(202) 726-4441
1818 New York Ave., NE Suite 115
Washington, DC
NGEN, LLC
(301) 531-9700
1101 Mercantile Lane
Washington, DC

provided by: 
Originally published at Internet.com


Author: Toby

It seems like all VBIDE.CommandBarEvents (Visual Basic Command Bar buttons) which you need to catch should be declared separately. For example, if you want to get particular event from Save button. You should do it something like this (And this example returns only one buttons click event):

This is written in VB help files

private withevents ce as CommandBarEvents ' Sub Test() Dim c as CommandBarControl set c = Application.VBE.CommandBars("Menu Bar").Controls(2) set ce = Application.VBE.Events.CommandBarEvents(c) End Sub ' private Sub ce_Click(byval CommandBarControl as Object, Handled as Boolean, CancelDefault as Boolean) ' Put event-handling code here End Sub '

So I made simple class for hooking these events. This class captures the events for every buttons click event.

How this works

This class ctlCmdEvent can act both as ParentClass and ChildClass.

SetEvents method collects all CommandBarControls and creates a new ChildClass for each control. This ChildClass is able to get its control event (Click). ChildClass directs the event back to ParentClass which rises event back to the first user object.
...

Read article at Internet.com site

Featured Local Company

Symbiont, Inc.

(202) 887-6800
1320 Fenwick Lane
Silver Spring, DC

Related Articles
- Interacting with .NET WinForms, Part 1 DC
We begin a detailed tutorial on getting started with Windows Forms in Microsoft.NET. It should enable you to start developing controls for GUI applications in the new framework.
- JavaBean Proxies DC
- Interacting with .NET WinForms, Part 2 DC
- QueryDef - a complete implementation of a dynamic recordset DC
Related Articles
- Interacting with .NET WinForms, Part 1 DC
We begin a detailed tutorial on getting started with Windows Forms in Microsoft.NET. It should enable you to start developing controls for GUI applications in the new framework.
- JavaBean Proxies DC
- Interacting with .NET WinForms, Part 2 DC
- QueryDef - a complete implementation of a dynamic recordset DC
Related Local Events
DC Chamber Technology Series: Session 4
Dates: 12/10/2009 - 12/10/2009
Location: Robert H. Smith School at the Ronald Reagan Building and International Trade Center
Washington, DC
View Details

ACIs 3rd Annual Carbon Capture and Sequestration Summit
Dates: 9/14/2009 - 9/15/2009
Location: Omni Shoreham Hotel
Washington, DC
View Details

3rd Carbon Capture and Sequestration Summit
Dates: 9/14/2009 - 9/15/2009
Location: Omni Shoreham Hotel
Washington, DC
View Details

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML