J
Jonas Kullenwall
I have written a macro to extract data from the active document. The macro
should be a part of an algorithm to auto detect headings. The problem is that
I get very long delays when accessing the DOM.
A code-snippet that show this behavior:
Dim nCount as Long
Dim oSents as Sentences
Dim sText as String
Set oSents = ActiveDocument.Sentences
if not oSent is nothing then
nCount = oSents.Count
if nCount > 1 then
sText = oSent.Item(nCount - 1).Text
endif
endif
For certain documents the Sentences::Count will take approx. 10s to execute.
Range::Text takes also approx 10 s to execute. The document is quite simple
with a TOC (~300 items), body text and a lot of heading. The document has 123
pages. I a would try to iterate through all sentences in this document it
would have taken to long time to be acceptable.
However, if I remove the table of content, then the execution time will be
below 1 s. Could someone explain why and is there any settings in Word that I
could modify to get rid of this problem? I have tried to run Word in safe
mode and also protected the document for editing with no performance
differences.
I am running Word 2003 and Win XP SP 2. My computer does not lack in
performance.
Jonas
should be a part of an algorithm to auto detect headings. The problem is that
I get very long delays when accessing the DOM.
A code-snippet that show this behavior:
Dim nCount as Long
Dim oSents as Sentences
Dim sText as String
Set oSents = ActiveDocument.Sentences
if not oSent is nothing then
nCount = oSents.Count
if nCount > 1 then
sText = oSent.Item(nCount - 1).Text
endif
endif
For certain documents the Sentences::Count will take approx. 10s to execute.
Range::Text takes also approx 10 s to execute. The document is quite simple
with a TOC (~300 items), body text and a lot of heading. The document has 123
pages. I a would try to iterate through all sentences in this document it
would have taken to long time to be acceptable.
However, if I remove the table of content, then the execution time will be
below 1 s. Could someone explain why and is there any settings in Word that I
could modify to get rid of this problem? I have tried to run Word in safe
mode and also protected the document for editing with no performance
differences.
I am running Word 2003 and Win XP SP 2. My computer does not lack in
performance.
Jonas