The bookmark is crashed by the text

G

Gérard Ducouret

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
 
H

Helmut Weber

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

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top