Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find out if a document has changed

Status
Not open for further replies.

PatternNut

Programmer
Jul 29, 2007
5
Hi,

I'm designing a Word add-in. The add-in has a modeless form that runs with the activedocument and helps authors to improve their writing.

As part of that, I have an array that provides information on every paragraph in the document. Everything works really well until the user has to make some changes in the document and starts deleting or adding paragraphs. When they do that, the array no longer corresponds to the correct paragraph.

I designed a system that re-aligns the paragraphs (based on variables such as number of words and first word). It re-aligns the paragraphs with more than 99% accuracy. That's accurate enough, but it's a bit too slow because it goes through the entire document like this (instantaneous in short documents but several seconds in very long ones):

For Each para in activedocument.paragraphs
lngParaNumber = lngParaNumber + 1
arrWordCount(lngParaNumber ) = para.range.words.count
Next para

Is there a better way to tell if the user has made changes? Is there a way to tell if the user activates the activedocument window instead of the form? Is there a way to tell if paragraphs are added or deleted? Is there a way to better link an array to each paragraph? Is there something else that I haven't thought of.

Thanks in advance for any ideas that you have.

Cheers,

PatternNut

 
helps authors to improve their writing." Care to elaborate on that? I would be interested in how you do that.

"Everything works really well until the user has to make some changes in the document and starts deleting or adding paragraphs. When they do that, the array no longer corresponds to the correct paragraph." Ummm, yes, it would, wouldn't it.


"I designed a system that re-aligns the paragraphs (based on variables such as number of words and first word)." What do you mean by re-align?

"Is there a better way to tell if the user has made changes? Is there a way to tell if the user activates the activedocument window instead of the form? Is there a way to tell if paragraphs are added or deleted? Is there a way to better link an array to each paragraph?"

1. Not really. There is no Change event in Word.
2. Not easily. I suppose you could set a hWnd type of variable and be constantly checking, but this seems silly. What exactly is the business case for this?
3. Not without counting them. How could it otherwise?
4. No. A For Each is fine. But again, what exactly is the business case?

BTW: I hope you realize what Word does with your code.
Code:
For Each para in activedocument.paragraphs
   lngParaNumber = lngParaNumber + 1
   arrWordCount(lngParaNumber ) = para.range.words.count
Next para

Say the variable para is the paragraph:

This is a sentence.

Youdo know that the range.words.count for the above = 6? Not 4. SIX.

When using Range.Words.Count, the period AND the paragraph mark are counted as separate words. Just like Range.Words.Last for ANY paragraph is....the paragraph mark.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top