Consulting

Results 1 to 4 of 4

Thread: Go to start of document with Word VBA

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Posts
    6
    Location

    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
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,378
    Location
    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
    Last edited by macropod; 07-12-2009 at 05:12 AM.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    VBAX Contributor
    Joined
    Feb 2009
    Posts
    104
    Location
    or even the start of the document"?
    try this:
    [vba]
    Selection.HomeKey Unit:=wdStory[/vba]

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "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
  •