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.
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.