Parse Huge Word Document by evaulating eash word
Posted on 2004-10-27
Ok, I have most of this figured out, but ran into a huge performance problem. I am parsing a Word Document by looking at each word and sorting it depending on the font color. It works GREAT until I hit around word 5000 then it really starts to slow down. Here is an idea of how I am coding it.
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim strFileName As String
Dim txtText As String
Dim lngColor As Long
Dim lngWord as long
strFileName = "D:test.doc"
Set appWord = New Word.Application
Set wrdDoc = appWord.Documents.Open(strFileName)
lngWord = 1
Do While lngWord < wrdDoc.Words.Count
txtText = wrdDoc.Words(lngWord).Text
lngColor = wrdDoc.Words(lngWord).Font.Color
Select Case lngColor
'do some code
lngWord = lngWord +1
Like I said, my code is working fine. It slows down terribly when I get above 5000 words and the document contains over 28000, so I really need to figure something else out. I am guessing that Word doesn't keep track of the last word I read, so it continuously starts from the very begining of the file to get to the next word specified.
Hope this makes sence and someone has a suggestion.