473,505 Members | 14,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need Document Close event handler

Hi, Group,

I am using C# program to launch a Word document in Word 2003. My C# program
will be sitting on "top most" while document opened. I would like to hook up
an event when Word document has been closed (not Word application), my
program will be closed automatically too.

I can't find the "Close" event in ActiveDocument. There are events for "New"
and "Open". How do I create event handler for document closed?

Thanks.
Eric
Nov 16 '05 #1
2 7794
Eric Li wrote:
I am using C# program to launch a Word document in Word 2003. My C# program
will be sitting on "top most" while document opened. I would like to hook up
an event when Word document has been closed (not Word application), my
program will be closed automatically too.

I can't find the "Close" event in ActiveDocument. There are events for "New"
and "Open". How do I create event handler for document closed?


Hi Eric,

the DocumentClass offers a DocumentEvents_Event_Close. The following
code works for me (Word 2003 and PIAs installed):

private void button1_Click(object sender, System.EventArgs e)
{
ApplicationClass app = new ApplicationClass();
object miss = System.Type.Missing;
DocumentClass doc = (DocumentClass) app.Documents.Add(ref miss, ref
miss, ref miss, ref miss);
app.Visible = true;
doc.DocumentEvents_Event_Close +=new
DocumentEvents_CloseEventHandler(doc_DocumentEvent s_Event_Close);
}

private void doc_DocumentEvents_Event_Close()
{
MessageBox.Show("Close event");
}

Cheers

Arne Janning
Nov 16 '05 #2
Hi, Arne,

Great! I will give it a try. Thanks.
Eric

"Arne Janning" <sp*****************@msn.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Eric Li wrote:
I am using C# program to launch a Word document in Word 2003. My C# program will be sitting on "top most" while document opened. I would like to hook up an event when Word document has been closed (not Word application), my
program will be closed automatically too.

I can't find the "Close" event in ActiveDocument. There are events for "New" and "Open". How do I create event handler for document closed?


Hi Eric,

the DocumentClass offers a DocumentEvents_Event_Close. The following
code works for me (Word 2003 and PIAs installed):

private void button1_Click(object sender, System.EventArgs e)
{
ApplicationClass app = new ApplicationClass();
object miss = System.Type.Missing;
DocumentClass doc = (DocumentClass) app.Documents.Add(ref miss, ref
miss, ref miss, ref miss);
app.Visible = true;
doc.DocumentEvents_Event_Close +=new
DocumentEvents_CloseEventHandler(doc_DocumentEvent s_Event_Close);
}

private void doc_DocumentEvents_Event_Close()
{
MessageBox.Show("Close event");
}

Cheers

Arne Janning

Nov 16 '05 #3

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

Similar topics

8
2001
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
1
1440
by: lawrence | last post by:
I'm trying to gain a better understanding of javascript by studying examples. I noticed this in an online tutorial. I don't get the use of "this". >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> You might want...
106
6345
by: xtra | last post by:
Hi Folk I have about 1000 procedures in my project. Many, many of them are along the lines of function myfuntion () as boolean on error goto er '- Dim Dbs as dao.database Dim Rst as...
7
4612
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks...
3
1466
by: Jason James | last post by:
Hi all, I have an application that needs to print numerous documents of different styles (either to the printer or print preview dialog). I have selected which document type to print by...
2
17379
by: pbd22 | last post by:
Hi. I have an event handler in VB.NET that gets called several times. The output of the event handler is XML that is being called by an xmlhttp request from the client. I am using a...
7
2906
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
2
1607
by: registry | last post by:
<%@Language="VBSCRIPT" CODEPAGE="1252"%> <html> <head> <title>Registry Network Hospital Detail</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
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
7471
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
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
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
4699
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.