Excel Hints

Results 1 to 4 of 4

Thread: Go to start of document with Word VBA

  1. #1

    Go to start of document with Word VBA

    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

  2. #2
    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:
    VB:
    Dim SelRng As Range 
    Set SelRng = Selection.Range 
     ' Do stuff
    SelRng.Select 
    
    
    Formatting tags added by mark007
    Last edited by macropod; 07-12-2009 at 05:12 AM.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    or even the start of the document"?
    try this:
    VB:
    Selection.HomeKey Unit:=wdStory 
    
    
    Formatting tags added by mark007

  4. #4
    "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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •