word automation - go to end of document

R

rodb_m

Hello,

I'm trying the following (OLE automation via Delphi, but I've tried the same
via VB and it gives the same result):
- opening a very large and complex MS Word document (+800 pages)
- jumping to the end of the document: selection.goto(wdGotoPage, wdGotoLast)
- jumping to the end of the page: selection.goto(wdGotoLine, wdGotoLast)
- start writing at the end of the document

Works OK for smaller documents but for large document there is a problem:
- opening the document: OK
- asking the total number of pages of the document using
selection.information[wdNumberOfPagesInDocument]: OK, e.g. 900
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: OK, is 1
- goto end of document using selection.goto(wdGotoPage, wdGotoLast)
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: OK, e.g. 900
- goto end of page using selection.goto(wdGotoPage, wdGotoLast)
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: NOK, e.g. 807
- start writing in the document: at page 807 instead of 900...


--> so it seems the jump to the end of the document doesn't work for large
document...
--> waiting a couple of seconds after the jump doesn't solve the problem
--> looping (jumping again when I see I'm not at the end) doens't solve the
problem

Anyone an idea?


thanks,

Ronny
 
D

Dave Lett

Hi,

Instead of using
selection.goto(wdGotoPage, wdGotoLast)
selection.goto(wdGotoLine, wdGotoLast)

You might try using
Selection.EndKey Unit:=wdStory, Extend:=wdMove
which takes you to the end of the document.

HTH,
Dave
 
R

rodb_m

Hello,

thanks for the answer, but...

tried it and it doesn't work: reacts exactly the same as my code. Using my
example document, he does not jump to page 919, but only to page 715...

Probably the code under the two possibilities is the same.


Ronny

"Dave Lett" schreef:
Hi,

Instead of using
selection.goto(wdGotoPage, wdGotoLast)
selection.goto(wdGotoLine, wdGotoLast)

You might try using
Selection.EndKey Unit:=wdStory, Extend:=wdMove
which takes you to the end of the document.

HTH,
Dave


rodb_m said:
Hello,

I'm trying the following (OLE automation via Delphi, but I've tried the same
via VB and it gives the same result):
- opening a very large and complex MS Word document (+800 pages)
- jumping to the end of the document: selection.goto(wdGotoPage, wdGotoLast)
- jumping to the end of the page: selection.goto(wdGotoLine, wdGotoLast)
- start writing at the end of the document

Works OK for smaller documents but for large document there is a problem:
- opening the document: OK
- asking the total number of pages of the document using
selection.information[wdNumberOfPagesInDocument]: OK, e.g. 900
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: OK, is 1
- goto end of document using selection.goto(wdGotoPage, wdGotoLast)
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: OK, e.g. 900
- goto end of page using selection.goto(wdGotoPage, wdGotoLast)
- asking the current pagenumber using
selection.information[wdActiveEndPageNumber]: NOK, e.g. 807
- start writing in the document: at page 807 instead of 900...


--> so it seems the jump to the end of the document doesn't work for large
document...
--> waiting a couple of seconds after the jump doesn't solve the problem
--> looping (jumping again when I see I'm not at the end) doens't solve the
problem

Anyone an idea?


thanks,

Ronny
 
T

Tony Jollans

What a very complex way of getting to the end of the document! Use Dave's
method.

When you open a document (in Print Layout view and, depending on the
Background Repagination setting, maybe also in Normal View), Word
repaginates the whole document and it can take some time. Until it has done
this, it can be slow getting to the end - maybe you just need to wait longer
(I'm not sure what you've tried).

But, do you actually want to *type* or are you adding text via automation?
You might be better using something like ..

ActiveDocument.Range.InsertAfter

rather than moving the Selection. I'm not sure whether that will get round
your problem but it is generally good practice to use non-Selection ranges
in code.
 

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