K
k-risc
I have different Word documents, that I want to convert to xml based
on the styles. Other operations have to be done as well, it's not only
about iteratin through the paragraphs (tables have to be taken care
of, for example).
But there is this loop:
p = 1
While p <= ActiveDocument.Paragraphs.Count
With ActiveDocument.Paragraphs(p).Range
ActiveDocument.Range(.Start, .End - 1).Select
End With
Select Case ActiveDocument.Paragraphs(p).Style
Case "Format 1"
do this
Case "Format 2"
do that
End Select
p = p + 1
Wend
The loop analyzes the content of the paragraph, it's format, and
inserts text at the beginning and/or the end, replaces the content,
changes the style of the paragraph.
It ran pretty fast for a smaller document, but now I have a big
document and the script runs very, very slow.
Therefore I wrote a test routine, that only executes the above while
loop, selects each paragraph, but does not do the select. It simply
selects each paragraph.
The smaller document contains 692 paragraphs, the test routine takes 5
seconds to run.
The bigger document contains 8210 paragraphs and takes 9 minutes and
28 seconds to run.
So it seems that the time per paragraph is like ten times bigger for
this file, making the whole script very slow.
What could be the cause for this?
I know that not only selecting each paragraph but changing it's
contents provokes re-alignment of the text which slows everything
down. That's for sure. But still I can see that with the smaller
document it goes much faster, for the longer document it's not only
slower by the factor of paragraphs it contains more, but there seems
to be something else slowing it dowwn drastically.
Regards,
Chrstian Kirchhoff
on the styles. Other operations have to be done as well, it's not only
about iteratin through the paragraphs (tables have to be taken care
of, for example).
But there is this loop:
p = 1
While p <= ActiveDocument.Paragraphs.Count
With ActiveDocument.Paragraphs(p).Range
ActiveDocument.Range(.Start, .End - 1).Select
End With
Select Case ActiveDocument.Paragraphs(p).Style
Case "Format 1"
do this
Case "Format 2"
do that
End Select
p = p + 1
Wend
The loop analyzes the content of the paragraph, it's format, and
inserts text at the beginning and/or the end, replaces the content,
changes the style of the paragraph.
It ran pretty fast for a smaller document, but now I have a big
document and the script runs very, very slow.
Therefore I wrote a test routine, that only executes the above while
loop, selects each paragraph, but does not do the select. It simply
selects each paragraph.
The smaller document contains 692 paragraphs, the test routine takes 5
seconds to run.
The bigger document contains 8210 paragraphs and takes 9 minutes and
28 seconds to run.
So it seems that the time per paragraph is like ten times bigger for
this file, making the whole script very slow.
What could be the cause for this?
I know that not only selecting each paragraph but changing it's
contents provokes re-alignment of the text which slows everything
down. That's for sure. But still I can see that with the smaller
document it goes much faster, for the longer document it's not only
slower by the factor of paragraphs it contains more, but there seems
to be something else slowing it dowwn drastically.
Regards,
Chrstian Kirchhoff