Microsoft.Office.Interop.Word.ApplicationEvents3_Event.DocumentChange not always firing

D

David Thielen

Hi;

I have an event handler for DocumentChange and when I have 2 Word
documents (Word 2007) up, when I switch between the two documents,
this event only fires about half the time.

I HAVE to have an event when switching documents because things change
- like what items are enabled in the ribbon menu. How can I get this
to always work or is there another event that always fires when
switching documents?

It doesn't stop working, it's just intermittent, works twice doesn't
once, does once, doesn't 3 times, does twice... Pretty random.

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Ji Zhou [MSFT]

Hello Dave,

Thanks for using Microsoft Newsgroup Support Service!

To enable or disable items on ribbon according to which Word document is
presented to user, it is recommended to use the Application.WindowActivate
event as the following:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WindowActivate += new
Microsoft.Office.Interop.Word.ApplicationEvents4_WindowActivateEventHandler(
Application_WindowActivate);
}

void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc,
Microsoft.Office.Interop.Word.Window Wn)
{
Globals.Ribbons.Ribbon1.button1.Enabled = false;
}

This event fires when any document window is activated. The following is
the related document in the MSDN:
http://msdn.microsoft.com/en-us/library/aa211901(office.11).aspx

Please let me know whether this works for your scenario.


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Ji Zhou [MSFT]

Hello Dave,

I want to add some comments about the
Word.ApplicationEvents3_Event.DocumentChange event. I create two Shared
Add-In projects to perform the test. One of them targets PIA2003, and
another targets PIA 2007. Both work fine. The DocumentChange event fires
when a new document is created, an existing document is opened, or another
document is made the active document, as MSDN document describes.

As far as I know, the internal implementation of the DocumentChange event
relies on the WindowActivate event, thus I suggested you try the
WindowActivate event. If the WindowActivate event still does not work for
your scenario, could you please provide more information of the issue's
context? Like whether the Office 2007 SP1 is installed, and whether you
use the Office 2003 PIA, the Office XP PIA or the IA generated by yourself.
It will be helpful if you can provide detailed reproduce steps.


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

Found it - our fault (sorry).

We have found that calling Word.Find() in the header/footer part of a
document causes DocumentChange to be called. In our DocumentChange
handler we call Find() to determine menu settings. Needless to say,
this locks up Word.

So we have a bunch of tests to make sure that DocumentChange() is not
being called for this reason. Only if we know it's safe do we then
call our internal DocChange() handler. It was tripping on one of those
tests.


Hello Dave,

I want to add some comments about the
Word.ApplicationEvents3_Event.DocumentChange event. I create two Shared
Add-In projects to perform the test. One of them targets PIA2003, and
another targets PIA 2007. Both work fine. The DocumentChange event fires
when a new document is created, an existing document is opened, or another
document is made the active document, as MSDN document describes.

As far as I know, the internal implementation of the DocumentChange event
relies on the WindowActivate event, thus I suggested you try the
WindowActivate event. If the WindowActivate event still does not work for
your scenario, could you please provide more information of the issue's
context? Like whether the Office 2007 SP1 is installed, and whether you
use the Office 2003 PIA, the Office XP PIA or the IA generated by yourself.
It will be helpful if you can provide detailed reproduce steps.


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

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