Some strange exceptions

V

Vladimir Kotlyarov

I've mafe a simple stress test for my Word 2003. In one large document (~700
pages) I've created a following macro:

Sub test
Dim s as String, i as Long
i = 0
Do While True
i = i + 1
Debug.Print i
s = ActiveDocument.Range.XML
ActiveDocument.Range.InsertXML s
Loop
End sub

And when i = 82, ActiveDocument.Range.InsertXML method fails and says it
cannot insert an XML string in this position.

I rewrote this code in C++, and detect that MSXML5 module raises an
exception deeply in assembly code.

What does it mean? An XML string (in s variable) is correct, it can be saved
to disk and loaded without problems in the next time, after I restart Word.

Help!!!
 
K

Klaus Linke

Hi Vladimir,

Just a guess: If you're inserting stuff, Word may need to keep old info from the Word document, and add new info from the WordML.

Say for example list templates:
If you have a few dozen list templates in use, then in 82 iterations the number of list templates could grow quite a bit, hitting some limit.

The only way to make sure would be to compare the strings s from different iterations.

Regards,
Klaus
 
V

Vladimir Kotlyarov

Hi Klaus,

It doesn't matter. Exception occurs even if I insert the same string, like
in following:

Dim s as String, i as Long
s = ActiveDocument.Range.XML
i = 0
Do While True
i = i + 1
Debug.Print i
ActiveDocument.Range.InsertXML s
Loop
Hi Vladimir,
Just a guess: If you're inserting stuff, Word may need to keep old info
from the Word document, and add new info from the WordML.
Say for example list templates:
If you have a few dozen list templates in use, then in 82 iterations the
number of list templates could grow quite a bit, hitting some limit.
 
K

Klaus Linke

Hi Vladimir,

Another idea:
How large is that document? Do you notice disk activity as the macro runs?

Maybe Word is creating lots of large temporary files to be able to undo all those changes.
You could try if putting in an ActiveDocument.UndoClear helps.

Regards,
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