1
votes

I place a bookmark within a word document table cell at the curser location. Now I want to move down one line after the bookmark, within the same table cell, and place another bookmark. I tried adding a carriage return after the bookmark, but the curser remains on the first line within the bookmark.

ActiveDocument.Bookmarks.Add Name:=bmItemNo, Range:=BMRange
'Adds carriage return after bookmark
BMRange.InsertAfter (Chr(13))

I also tried moving my curser to the end of the line and down 1 line, but it jumps out of the table cell:

ActiveDocument.Bookmarks.Add Name:=bmItemNo, Range:=BMRange
'Adds carriage return after bookmark
BMRange.InsertAfter (Chr(13))
Selection.EndKey unit:=wdLine, Extend:=wdMove
Selection.MoveDown unit:=wdLine, Count:=1, Extend:=wdMove

My bookmark can also word wrap with multiple lines.

How do I move my curser to the next line after a bookmark?

1

1 Answers

1
votes

Your code almost works. You don't define or tell us what BMRange is, so I made some assumptions. Always use 'Option Explicit' for that reason. You want to explicitly define all variables. Also, inserting text and the cursor are not related. Get into the practice of thinking with Ranges to build within a document, not the insertion point. Although my code example is not the best for that, it does illustrate your question.

I can't get your results but it's what I think you wanted. Is that right?

Option Explicit
Public Sub Test()
    Dim BMRange As Range
    Set BMRange = Selection.Range

    ActiveDocument.Bookmarks.Add Name:="One", Range:=BMRange

    'Adds carriage return after bookmark
    BMRange.InsertAfter (Chr(13))

    Selection.EndKey unit:=wdLine, Extend:=wdMove
    Selection.MoveDown unit:=wdLine, Count:=1, Extend:=wdMove

    Set BMRange = Selection.Range
    ActiveDocument.Bookmarks.Add Name:="Two", Range:=BMRange
End Sub