Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting text between bookmarks (2002 SP3)

    In VBA how do I select all text from beginning of line at Bmrk1 to the end of line at Bmrk2?
    Regards,
    Peter

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Selecting text between bookmarks (2002 SP3)

    I suspect there are more elegant approaches, but until somebody else posts one, this will do the job:

    Dim lngStart As Long
    Selection.GoTo What:=wdGoToBookmark, Name:="Bmrk1"
    Selection.StartOf wdLine
    lngStart = Selection.Start
    Selection.GoTo What:=wdGoToBookmark, Name:="Bmrk2"
    Selection.EndOf wdLine
    Selection.SetRange lngStart, Selection.End

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Selecting text between bookmarks (2002 SP3)

    There are plenty of things that can go wrong with this but recording the steps can be simplified to :
    <pre> Selection.GoTo What:=wdGoToBookmark, Name:="bkmk1"
    Selection.MoveLeft Unit:=wdCharacter, count:=1
    Selection.HomeKey Unit:=wdLine
    Selection.Extend
    Selection.GoTo What:=wdGoToBookmark, Name:="bkmk2"
    Selection.EndKey Unit:=wdLine
    Selection.ExtendMode = False</pre>


    The gotchas where you may run into problems are:
    1. bkmk2 starts earlier than bkmk1
    2. bkmk2 ends earlier than bkmk1
    3. bkmk2 includes a return at the end of a paragraph.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Selecting text between bookmarks (2002 SP3)

    Using a mobile so I can't search... we had a thread just like this in the past year or two.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting text between bookmarks (2002 SP3)

    Worked like a charm.
    Thanks heaps
    Regards,
    Peter

Posting Permissions

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