473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Word BeforePrint Event is not raised

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.Wor d.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
Aug 10 '05 #1
3 2852
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.
"nmueggler" wrote:
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.Wor d.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

Aug 10 '05 #2
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?

"nmueggler" wrote:
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.
"nmueggler" wrote:
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.Wor d.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

Aug 12 '05 #3
So, one step above didn't work either....
But I got a workaround now, not a lovely one, but the event is raised all
the time.

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

while(wordDoc.Application.BackgroundPrintingStatus == 0)
{
Thread.Sleep(5);
}
}

I'm waiting 5 milliseconds until someone is printing. If I go up with the
time then the application losing a noticeable amount of performance.

I don't know why this is helping and I'm wondering me, that no one other
ever had such a problem ?!
"nmueggler" wrote:
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?

"nmueggler" wrote:
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.
"nmueggler" wrote:
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.Wor d.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

Aug 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Raju Joseph | last post by:
Hi All, I have a small problem at hand and am looking for suggestions. I have created a wrapper for word 2000 for our application which is in VB.NET 2003. Everything works fine in the sense...
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
2
by: Charles Law | last post by:
I may have asked this before, but what is the purpose of both these functions? Is there a time when one should be called over the other? Does one supersede the other, or do they both have their...
2
by: shuckjunkmail | last post by:
It was suggested that I re-submit this question as a new post rather than adding onto an old and unanswered post. The basic problem has to do with the .NET datagrid and sorting. I am having...
4
by: nmueggler | last post by:
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...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
4
by: maminx | last post by:
hello all. i have html page to be printed out..it's generated by the button print like below <input type="button" name="btn_print" value="Print Invoice" onClick="javascript:window.print();"> of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.