Hello,
How can I write some text at a Word bookmark, via VBA, without losing the
bookmark, whether or not the bookmark currently encloses any text?
Thanks for your help,
Gérard
Helmut Weber - 26 Feb 2006 19:29 GMT
Hi Gérard,
for encluding bookmarks, like [some text]:
Public Sub NewText(sBkm As String, sTmp As String)
Dim rTmp As Range
With ActiveDocument.Bookmarks
If .Exists(sBkm) Then
Set rTmp = .Item(sBkm).Range
rTmp.Text = sTmp
.Add Name:=sBkm, Range:=rTmp
End If
End With
End Sub
Sub test4001()
NewText "Mark01", "2nd Text"
End Sub
The bookmark gets lost and has to be recreated.
With excluding bookmarks, like ][,
it's not a problem anyway.
There is a nice tool from Greg Maxey:
http://gregmaxey.mvps.org/Bookmark_Tool.htm

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Doug Robbins - Word MVP - 26 Feb 2006 22:11 GMT
See the article "Inserting text at a bookmark without deleting the bookmark"
at:
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hello,
> How can I write some text at a Word bookmark, via VBA, without losing the
> bookmark, whether or not the bookmark currently encloses any text?
> Thanks for your help,
>
> Gérard