Equivalent of Workbook_BeforePrint in C++?

C

ccccoder

Hi,

I need to add a new functionality to an existing Excel addin developed in
C++ (ATL/COM), which would try to validate the workbook data before the
workbook is printed. If the data validation fails, then I want Excel to
cancel the print job.

We have an event sink, and get the event just fine when printing is
requested. The problem is, how could I tell Excel to cancel the job?

In VBA, I can set the cancel flag to true in Workbook_BeforePrint. But in
C++, there does not seem to have an equivalent of the Workbook_BeforePrint
subroutine, and no way to replace it like in VBA.

But how I tell Excel to cancel the print job in that case? Doing the work in
VBA is not an object, as the project was initially in VBA, and we rewrote
everything in C++ due to all kinds of macro loading problems. So, no way to
go back. Not an option to use interop library either, as we don't do managed
code.

Thanks in advance

ccccoder
 
C

ccccoder

As a related question, the event sink is implementing the Invoke() method
from the IDispatch interface:

STDMETHODIMP MyEventListener::Invoke(DISPID dispIdMember, REFIID riid, LCID
lcid,
WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr)

When events are fired, I can get them here, including the before_print
event. As an investigation to see how I could tell Excel to cancel the print
request, I'd like to know what does Excel sends in to this method, especially
in pDispParams. Unfortunately, the documentation is not saying anything. I
know it is an IDispatch object, but no way to figure out what it is. Could
someone tell what am I supposed to receive here when the print event is fired?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top