If you want to handle COM events, you're probably better of writing a COM
add-in rather than a Excel 4 (XLL) add-in.
Using the Visual Studio .NET wizard, select File/New Project, Other
Projects, Extensibility Projects, Shared Add-in, and follow the wizard steps
to create the project.
The other way of making one is to create a simple COM object:
1. Add the following to stdafx.h. For VC++ 6.0, change
"progid:Excel.Workspace" to "C:\Path\Excel.exe".
// Microsoft Add-In Designer Object Library
#import "progid:MSAddnDr.AddInDesigner" auto_rename, auto_search
// Microsoft Excel 10.0 Object Library
#pragma warning(push)
#pragma warning(disable : 4192) // automatically excluding 'name'
while importing type library 'library'
#pragma warning(disable : 4298) // identifier in type library
'library' is already a macro; renaming to '__identifier'
#pragma warning(disable : 4337) // cross-referenced type library
'typelib1' in 'typelib2' is being automatically imported
#import "progid:Excel.Workspace" auto_rename, auto_search,
no_implementation
using Excel::IRtdServer;
#pragma warning(pop)
2. Add the following to the .rgs file. Replace 'Plugin.Progid' with your
simple objected progid.
HKLM
{
NoRemove Software
{
NoRemove Microsoft
{
NoRemove Office
{
NoRemove Excel
{
NoRemove AddIns
{
'Plugin.Progid'
{
val
Description = s 'My plug-in short name'
val
FriendlyName = s 'Description of my plug-in'
val
LoadBehavior = d 3
}
}
}
}
}
}
}
3. Add the following to your class inheritance. NOTE the __uuidof
(Excel::AppEvents) is NOT a typo, even though the Excel::IAppEvents is being
implemented. Visual C++ .NET 2003 (and possibly other versions) doesn't
understand the wierd stuff Office puts in its type library, such as
implementing the dispinterface for the events directly rather than
inheriting from the vtable interface.
public IDispatchImpl<Excel::IAppEvents,
&__uuidof(Excel::AppEvents), &__uuidof(Excel::__Excel),
/* wMajor = */ 1, /* wMinor = */ 4>,
public IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2,
&__uuidof(AddInDesignerObjects::_IDTExtensibility2),
&__uuidof(AddInDesignerObjects::__AddInDesignerObjects),
/* wMajor = */ 1, /* wMinor = */ 0>
Note that COM add-ins require Excel 2000 or later.
Regards,
Aaron Queenan.