Question

I have a Worddocument with bookmarks. From Excel I write cell content to the places where I set the bookmarks.

My problem: You can still see the bookmarks.

What I tried:

First I used a placehoder bookmark with

.item("Name1").Range.InsertAfter Rep.NName1

Second I used an enclosing bookmark with

.item("Name1").Range.InsertAfter Rep.NName1

and

.item("Name1").Range.InsertBefore Rep.NName1

I still cannot get rid of the bookmarks.

All I could do is using the sledgehammer approach and delete them but I think there should be a way to replace them during the insert.

Source

Was it helpful?

Solution

If you want to overwrite the bookmark (ie replace any text contained within the bookmark and delete the bookmark itself), you can just set the Text property of the Bookmark's range:

    .Item("Bookmark1").Range.Text = "Some new text"

If you want to replace the content of the existing bookmark but identify the new text with the bookmark, you'll need to replace the text then mark the new text as the bookmark:

    Dim bmRange As Range
    Set bmRange = .Item("Bookmark2").Range
    bmRange.Text = "Some new text"
    .Add Name:="Bookmark2", Range:=bmRange
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top