word is slowing down when I am parsing a document

M

Me

I am parsing documents to convert them to html
parsing the document is done using this code

For Each oWordSection In oWordApp.Selection.Sections
For Each owordPar In oWordSection.Range.Paragraphs
If owordPar.Range.Information(wdWithInTable) = False Then
writeParToHTML iFile, owordPar, flVoorschrift, TOCDepth
flTableFound = False
Else
' we zijn aan een tabel, we schrijven deze in zijn geheel
weg
If flTableFound = False Then
' ok we schrijven de volgende tabel weg
closePrevStyle iFile
iTableCount = iTableCount + 1
writeTableToHTML iFile,
oWordSection.Range.Tables.Item(iTableCount), flVoorschrift
flTableFound = True
Else
' we hebben deze tabel al weggeschreven
End If
End If
Next
Next

My code does work but some documents are parsing really slow.
It seems that I have this problem only when parsing docs containing one or
more tables
The more tables I have got the slower it works.

Does anyone knows what my be the problem and what the solution for this
problem is.

thanks in advance
 
M

Malcolm Smith

I have seen something like this before.

It seems that iteration is slower than using pointers. Now, my Flemish
isn't all that it ought to be so I'm guessing at some of your comments and
that something interesting is happening in the writeTableToHTML()
procedure.

You are passing a pointer of the discovered table in. What happens in
there?


Now, as for seeing this before; I was given some code which also parsed
documents and it did the usual:

For nWord - 1 to ActiveDocument.Words.Count
sWord = ActiveDocument.Words(nWord)

and so on. It worked well for a small one or two page document. Then I
threw at it a 300+ page document and it started to crawl the further
through the document it went.

I wonder if anything similar is happening in the writeTableToHTML()
routine?

Malc
 
M

Me

this is the code I am using in my writeTableToHTML routine

For Each oWordRow In oWordTable.Rows
iRowCount = iRowCount + 1
Print #iFile, "<tr>"
For Each oWordCell In oWordRow.Cells
If iRowCount = 1 And oWordCell.Range.Bold = True Then
Print #iFile, "<td align=""center"" bgcolor=""#FFFFCC"">"
Else
Print #iFile, "<td valign=""top"">"
End If
For Each owordPar In oWordCell.Range.Paragraphs
writeParToHTML iFile, owordPar, flVoorschrift, "0"
Next
closePrevStyle iFile
Print #iFile, "</td>"
Next
Print #iFile, "</tr>"
Next

What you describe here is exactly what is happening to my documents
as soon as my code reaches another table, it is slowing down even more
 
M

Malcolm Smith

I take it that 'oWordTable' is the table passed in?

There is nothing here which would slow things down unless there is
something in one of the procedures which is called from this one.

- Malc
www.dragondrop.com
 
M

Me

yes 'oWordTable' is the table passed in
and the only thing happening now is converting the tekst in the paragraph to
html
and that is the same procedure I use as I do in text wich is not in tables
anyone an idea ?
 
K

Klaus Linke

Word will slow down generally if you have a document with lots of tables.

But if you are sure that the macro starts out fast, processing the first
tables quickly, and then slows down, you definitely must have some line(s)
of code that force Word to process the file from the start each time.
It's the problem Malc mentioned.

oWordSection.Range.Tables.Item(iTableCount)
can slow down significantly, because Word loops from the start to the table
with index "iTableCount" to retrieve it.

Haven't checked it out, but perhaps even in the line
If oWordPar.Range.Information(wdWithInTable) = False Then ...
Word loops all the tables from the start, until it arrives at
oWordPar.Range.

In both cases, the processing time isn't proportional to the lenght of the
document any more. Some part of the code takes a time proportional to the
square of the length.

Perhaps you can loop every table in the desired range to inserts the HTML
tags you want... so you can avoid to retrieve the table from its index. Or
you might work on a copy of the document, and delete the stuff that you have
already processed.

I would also try to rewrite the code so it converts the text to tables as
early as possible.

Hope it helps,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top