(Solved!) Using Range to insert bookmark in table cell

User avatar
Charles Kenyon
5StarLounger
Posts: 612
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

(Solved!) Using Range to insert bookmark in table cell

Post by Charles Kenyon »

:clapping: I have attempted the following code to insert a bookmark The last statement is not accepted.

Code: Select all

    Dim oRange As Range
    Set oRange = ActiveDocument.Tables(1).Cell(2, 2).Range
    ActiveDocument.Bookmarks.Add("mymark",oRange.start)
I can select the cell and add the bookmark but prefer to use a range.
Last edited by Charles Kenyon on 06 Nov 2019, 22:18, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78439
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using Range to insert bookmark in table cell

Post by HansV »

The second argument of Bookmarks.Add should be a range, not a position in the document. You can use:

Code: Select all

    Dim oRange As Range
    Set oRange = ActiveDocument.Tables(1).Cell(2, 2).Range
    oRange.Collapse
    ActiveDocument.Bookmarks.Add "mymark", oRange
Best wishes,
Hans

User avatar
Charles Kenyon
5StarLounger
Posts: 612
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Using Range to insert bookmark in table cell

Post by Charles Kenyon »

Thank you.