Hi, Helmut,
thanks again for your answer!
I thought I could improve the performance by using find instead of the
range property since it seems to be very slow. First I noticed that the
performance of my code was acceptable (1 or 2 seconds) with
' Needs about 2 seconds
For Each parag In myDoc.Paragraphs
With parag
WScript.Echo .Range.Text ' just for demonstration
End With
Next
But it needed 56 (!) seconds when I add the test whether the paragraph
is part of a table:
' Needs about 56 seconds
For Each parag In myDoc.Paragraphs
With parag
If .Range.Information(wdWithInTable) = True then
' do something
End If
WScript.Echo .Range.Text ' just to do something
End With
Next
[...]
> What is it, that you want to do?
> And how does your doc look?
> 100 pages? 200 Tables?
[...]
That's about the size of my docs.
The docs contain Questions and Answers but are structured differently
because they have different authors: Some are structured just with
paragraphs, others have tables where the questions in the left column
and answer in the right column. I want to extract the questions and the
assigned answers and output it in a concrete XML format.
I want to analyze first which kind of structure the doc has (table based
or only paragraphs) and then create the XML file.
I wonder how .Range.Information() needs so much time. Any ideas?
--Conny
(from Munich)
Helmut Weber - 02 Jan 2005 14:52 GMT
Hi Conny,
>I wonder how .Range.Information() needs so much time.
>Any ideas?
well, ranges in tables are something special,
as I think Word organizes tables internally in a linear way.
The may not be 2 dimensional arrays really,
but need a conversion each time from 1 dimensional
to 2 dimensional data. But that is mere speculation.
Selection, however, is sometimes, not to say always, faster in tables.
Here is what I found out, for 10 pages and 10 tables:
Sub TestSlow()
Dim bInT As Boolean ' in Table
Dim oPrg As Paragraph
Dim lTim As Long
lTim = Timer
Application.ScreenUpdating = False
For Each oPrg In ActiveDocument.Paragraphs
bInT = oPrg.Range.Information(wdWithInTable)
Next
MsgBox Timer - lTim ' 22 Seconds
End Sub
' ---
Sub TestFast()
Dim bInT As Boolean ' in Table
Dim oPrg As Paragraph
Dim lTim As Long
lTim = Timer
Application.ScreenUpdating = False
For Each oPrg In ActiveDocument.Paragraphs
oPrg.Range.Select
bInT = Selection.Information(wdWithInTable)
Next
MsgBox Timer - lTim ' 1 Second
End Sub
Greetings from Landsberg am Lech
Bavaria, a region in Europe
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Conny Roloff - 02 Jan 2005 20:33 GMT
Hi, Helmut,
[...]
> Sub TestFast()
> Dim bInT As Boolean ' in Table
[quoted text clipped - 8 lines]
> MsgBox Timer - lTim ' 1 Second
> End Sub
That helps a lot! I got it down to 4 seconds instead of 56!
Danke, Helmut.
--Conny