Consulting

Results 1 to 5 of 5

Thread: Selection with VBA for Word

  1. #1
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location

    Selection with VBA for Word

    Line 1
    Line 2
    Line 3
    Line 4
    ......
    the end

    I have a multi-page text. Is there a way to choose from the 4th line down at the end of that text? Thank you all.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Yes, but we'd need to know a lot more about the document structure and the content you're working with.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    If by line, you mean paragraph and if you mean the fourth line on page one then:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oRng As Range
      Set oRng = ActiveDocument.Range.Paragraphs(4).Range
      oRng.Collapse wdCollapseEnd
      oRng.End = ActiveDocument.Range.End
      oRng.Select
    lbl_Exit:
      Exit Sub
    End Sub
    ... however, as Paul states, that works on the very limited conditions given.
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location
    Ok, thank you gmaxey

  5. #5
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    @lamnbj Has either of Paul's or Greg's responses been helpful? if not, can you indicate where they seem to come unstuck?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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