Word BeforePrint Event is not raised

G

Guest

Hi

I'm working on a Word 2003 mail merge component for a windows client.
My problem is that the BeforePrint Event ist not raised if the user is
printing directly out of word, but if I'm running the PrintOut command in the
code it is working!

I'm using Office 2003 with the appropriate PIA's.

The code looks like this:

public void Preview()
{
Document wordDoc = OpenDocument();
wordDoc.Application.Visible = true;
}

privat e Document OpenDocument()
{
Document wordDoc = null;
ApplicationClass wordApp = new ApplicationClass();
wordApp.DocumentBeforePrint += new
ApplicationEvents4_DocumentBeforePrintEventHandler(WordPrint_BeforePrint);

try
{
wordDoc = wordApp.Documents.Add(ref template, ref _missingValue,
ref
_missingValue, ref _trueValue);
wordDoc.MailMerge.Destination =
WdMailMergeDestination.wdSendToNewDocument;

wordDoc.MailMerge.Execute(ref _falseValue);
wordApp.ActiveDocument.SaveAs(ref fileName, ref _missingValue, ref
_missingValue, ref _missingValue, ref _missingValue, ref _missingValue, ref
_missingValue, ref _missingValue, ref _missingValue, ref _missingValue, ref
_missingValue, ref _missingValue, ref _missingValue, ref _missingValue, ref
_missingValue, ref _missingValue);

wordApp.Documents.Close(ref _falseValue, ref _missingValue, ref
_missingValue);

wordDoc = wordApp.Documents.Open(ref fileName, ref _missingValue,
ref _missingValue, ref _missingValue, ref _missingValue, ref _missingValue,
ref _missingValue, ref _missingValue, ref _missingValue, ref _missingValue,
ref _missingValue, ref _trueValue, ref _missingValue, ref _missingValue, ref
_missingValue, ref _missingValue);

}

private void WordPrint_BeforePrint(Microsoft.Office.Interop.Word.Document
doc, ref bool cancel)
{
// Do some stuff
}

It is really important that I can catch the BeforePrint event for my
application.

Can anyone help me?

Thanks
Nicolas
 
G

Guest

It is working....
But only in a simple test project and not in my application. I'll make my
test project more and more complex and will post it later, what's could wrong
with it.
 
G

Guest

Maybe I figured out what the problem could be. It looks like a failure in the
..NET Framework but I'm not sure...
I've im running the same routine one step above the event is raised but one
step deeper it doesn't work anymore. It looks like a stack or something's
flooding and the callback could not found anymore...

As workaround I'll put all the stuff one step above and changing the design
a little bit.

Has anyone ever had such a problem?
 

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