Range.Find.Execute generates a DocumentChange event

D

David Thielen

In Word 2003, the following code - only if the selection is in the header,
generates an ApplicationEvents3_Event.DocumentChange event.

Range range = applicationObject.Selection.Range.Duplicate;
range.Start = 0;
range.End = 2;
range.Find.ClearFormatting();
range.Find.Forward = forward;
range.Find.Text = text;
range.Find.Wrap = WdFindWrap.wdFindStop;

object missingValue = Type.Missing;

range.Find.Execute(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);

Any idea why it does this and how to stop it? This occurs only if the
selection is in the header.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

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

Jialiang Ge [MSFT]

Hello Dave,

From your post, my understanding on this issue is: you want to know how to
avoid the DocumentChange event when Find.Execute is called on a range in
Word document's Header or Footer. If I'm off base, please feel free to let
me know.

I reproduced this issue in my side and sent it to the development team to
see if it is a known issue of Word. Currently, a workaround is to
temporarily remove the DocumentChange event when Find.Execute is called:
ApplicationEvents4_DocumentChangeEventHandler handler = new
ApplicationEvents4_DocumentChangeEventHandler(application_DocumentChange);
¡­ ¡­
if (range.StoryType != WdStoryType.wdMainTextStory)
application.DocumentChange -= handler; // temporarily remove the event
handler
result = range.Find.Execute(ref text, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);
if (range.StoryType != WdStoryType.wdMainTextStory)
application.DocumentChange += handler; // restore the event handler.

I will get back to you as soon as possible. Thank you for your patiences.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

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

Jialiang Ge [MSFT]

Hello Dave,

According to a consultant's response, this behavior does seem a bug of
Office 2003. But in Office 2007, the issue cannot be reproduced. I will
file a bug for this issue and record it into our internal database for
future reference. Currently, a wordaround is to disable the event when
Find.Execute is called as I posted in the last message. Thank you again for
your sharing.

If you have any other concerns or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hi Dave,

If you need further assistance, feel free to let me know. I will be more
than happy to be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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