MoveRight in table fails at 1%: bug? workaround?

M

Mic

Hi, does anyone know sth. about erros at Selection.MoveRight command?

I'm having a lot of trouble at an automatic function creating a Word
Document. VBA code runs for several hours (>5h) creating about 500 Documents,
each 1 to 50 pages containing a table layout (7 columns) and about 3 to 30
rows per page. Some table cells contain images (rather small, about 2x3'').

The error means Word is not doing a good job at creating a 2000 pages
pricelist every week. This is "Enterprise cristical" if documents would not
be re-viewed page by page.

The code is started from a MS Access Database (using a Word.Application with
GetObject("Word.Application") and so on...). All components are Office2003.
Language: German (should not cause trouble anyway).

Error: Error.Number: 2147417851, Error.Description: Method _MoveRight_
failed for object _Selection_
Error occurs at VBA command:
Word.Application.Selection.MoveRight Unit:=wdCell

Definately the selection mark is in the table at a cell when the error occurs.

It seems the Word.Application instance does not work properly after having
run some time. Errors do not occur at the same place at the same document,
but tend to strike long documents (>30 pages) more likely, when simple text
entries (by Selection.TypeText) need 10 times as long as they do in short
documents.

Hints and imagination about pagination have failed up to now, errors do not
only occur when moving right at the bottom of a page. The Word process
(TaskManager) looks ok, is not using more memory than normal. Everything
about the errors looks like being arbitrary.


Does anyone know something like a known bug about MoveRight? Is there a
workaround at least beeing able to minimize or limit errors? Could I do
anything not to get a 1% drop out rate?

Thanks a lot.
 
J

Jean-Guy Marcil

Mic was telling us:
Mic nous racontait que :
Hi, does anyone know sth. about erros at Selection.MoveRight command?

I'm having a lot of trouble at an automatic function creating a Word
Document. VBA code runs for several hours (>5h) creating about 500
Documents, each 1 to 50 pages containing a table layout (7 columns)
and about 3 to 30 rows per page. Some table cells contain images
(rather small, about 2x3'').

The error means Word is not doing a good job at creating a 2000 pages
pricelist every week. This is "Enterprise cristical" if documents
would not be re-viewed page by page.

The code is started from a MS Access Database (using a
Word.Application with GetObject("Word.Application") and so on...).
All components are Office2003. Language: German (should not cause
trouble anyway).

Error: Error.Number: 2147417851, Error.Description: Method _MoveRight_
failed for object _Selection_
Error occurs at VBA command:
Word.Application.Selection.MoveRight Unit:=wdCell

Definately the selection mark is in the table at a cell when the
error occurs.

It seems the Word.Application instance does not work properly after
having run some time. Errors do not occur at the same place at the
same document, but tend to strike long documents (>30 pages) more
likely, when simple text entries (by Selection.TypeText) need 10
times as long as they do in short documents.

Hints and imagination about pagination have failed up to now, errors
do not only occur when moving right at the bottom of a page. The Word
process (TaskManager) looks ok, is not using more memory than normal.
Everything about the errors looks like being arbitrary.


Does anyone know something like a known bug about MoveRight? Is there
a workaround at least beeing able to minimize or limit errors? Could
I do anything not to get a 1% drop out rate?

Thanks a lot.

Without seeing the relevant code, it is hard to venture an answer.

Meanwhile, the fact that you use "MoveRight" means that you are using the
Selection object. Using the Selection object makes for more convoluted code
that is less reliable and runs much slower, as you have observed.

Since you are creating hundreds of documents, you should rewrite the code to
use the Range object instead. It will run a lot faster and will be very
stable.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Klaus Linke

It might also help to clear the undo buffer from time to time in your code:
ActiveDocument.UndoClear

If you look for them, you'll probably notice that Word creates lots of large
temporary files as your macro runs, so that all changes can be undone.
Managing all those temporary files puts quite a burden on Word, and if you
remove that burden, this may allow your macro to run faster and without
running into problems.

That said, I've run quite often into problems where simple commands suddenly
stopped working in macros when working with tables. If I have some time, I'd
like to make some reproducable cases and make sure Microsoft gets the bug
reports. But these bugs seem really hard to pin down: Sometiimes a test case
I produced will run fine the next day, on the same document and the same
machine.

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