Consulting

Results 1 to 4 of 4

Thread: Creating a Range Object between Bookmarks

  1. #1
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location

    Creating a Range Object between Bookmarks

    Ever get that feeling after laying off coding for a while you forget how to do it?

    Trying to Set myRange = text between two bookmarks. I've tried several variations of this and can't get it to work without throwing an error of one sort or another:

    Set myRng = ActiveDocument.Range(Start:=ActiveDocument.Range.Bookmarks(bkmkTOCStartNm).start, End:=ActiveDocument.Range.Bookmarks(bkmkTOCEndNm).end)
    
    Not sure what I'm doing wrong here.

  2. #2
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    OK, I think it's because the bookmarks are in a header.

  3. #3
    That's part of it

    Set myRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).RangemyRng.Start = myRng.Bookmarks("bkmkTOCStartNm").Range.End
    myRng.End = ActiveDocument.Bookmarks("bkmkTOCEndNm").Range.Start
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    This works (thanks, gmayor):

        Dim myRng As Range
        Set myRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
        myRng.Start = myRng.Bookmarks("T1").Range.End
        myRng.End = ActiveDocument.Bookmarks("T2").Range.Start
        myRng.Select

Posting Permissions

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