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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Chokes with too many comments?

Status
Not open for further replies.

PDO1

Programmer
Jul 3, 2008
3
0
0
US
Word crashes (total shut down) when I execute vba code that inserts comments in a word document after a large number of comments (~1000).
Synopsis: I have written code that iterates through each word in a document (>50,000 words) and compares the word to a table (collection) using a modified binary search. If it finds a match, it determines if the search element is a phrase and then compares the correct amount of words to the phrase. If there is still a match, it selects the word/phrase and inserts a comment.

After a lot of troubleshooting, I've determined it is the Insert Comment that causes the problem.
*****code******
With ActiveDocument
.Comments.Add Range:=Selection.Range, _
Text:=colComment.Item _(lngCurrentIndex) End With
****end code******
(note colComment is a table (VB Collection) with a text entry of up to 40 words.
The crash will occur after about 15000 words into the document with maybe 1000 comments inserted.. I have set the following (no help):
****code****
Options.CheckGrammarAsYouType = False
Options.CheckGrammarWithSpelling = False
Options.CheckSpellingAsYouType = False
ActiveDocument.ShowGrammaticalErrors = False
ActiveDocument.ShowSpellingErrors = False
Application.ScreenUpdating = False

*end code*********
To make it run, sort of, I inserted a DoEvents after each 5000 words. I can also get through it by putting a stop after each ~ 5000 words and then click on continue. This makes me believe it isn't a hard code issue with a specific phrase or word. It has something to do with Word's ability to process the screen buffer modifications.

 
The fact that DoEvents makes a difference means you are doing something that queues up actions - possibly related to the screen buffer though I wouldn't expect that.

The first thing I would do is stop using Selection. In order to do your comparison you must have a Range, so just use that rather than selecting and using the Selection.

I'm not sure that any of the options you have set are relevant - either to the process or the problem.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
I would agree with Tony. If you used a Range, rather than Selection, then there IS no screen buffer issue.

You do not mention version, but there are limits to the number of comments. Although with 2007, I doubt if anyone will ever reach that limit - 2,147,483,647 !

The limit for previous versions is 16,380.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks for the response. I changed to range and the crash problem was solved. No need for DoEvents. Now if I could only make it run faster... I have more work to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top