VBA Express
Go to start of document with Word VBA [Archive] - VBA Express Forum

PDA

View Full Version : Go to start of document with Word VBA



Jacko_B
07-11-2009, 11:04 PM
I am adding a large number of lines to a table in Word, using VBA. The number of lines varies, but it is usually over several pages.

After the transfer of data to the table, how do I get back to the start of the table, or even the start of the document?

I have tried several statements, but all were unsuccessful

regards,
Jacko

macropod
07-12-2009, 04:59 AM
Hi Jacko,

Ordinarily, you should be able to do whatever you need to without the document having to scroll and, hence, needing to return to the start of the document afterwards. You can do this by using Range-based expressions instead of Selection-based expressions. Some complex Find/Replace operations are an exception (because of the need to use Selection-based expressions).

What is the code you're using that means you need to "get back to the start of the table, or even the start of the document"?

FWIW, to return to the place you had selected before executing a piece of code you can use something like:
Dim SelRng As Range
Set SelRng = Selection.Range
' Do stuff
SelRng.Select

joms
07-12-2009, 06:29 AM
or even the start of the document"?
try this:

Selection.HomeKey Unit:=wdStory

fumei
07-13-2009, 12:05 PM
"I have tried several statements, but all were unsuccessful"

Please post what you have tried.

If you want to go back (that is, make the cursor, the Selection) to the start of the table you are working with, the best way - including actually working with the table - is to use a table object.