Delete text of bookmark?

E

Ed

I can add text to a bookmark, but for some reason I can't delete it or
overwrite with "". I'm using
ActiveDocument.Bookmarks("LeftOffHere").Select
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = ""
ActiveDocument.Bookmarks("LeftOffHere").Delete
The bookmark deletes, but the text is still there! What am I doing wrong?
Ed
 
J

Jean-Guy Marcil

Ed was telling us:
Ed nous racontait que :
I can add text to a bookmark, but for some reason I can't delete it or
overwrite with "". I'm using
ActiveDocument.Bookmarks("LeftOffHere").Select
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = ""
ActiveDocument.Bookmarks("LeftOffHere").Delete
The bookmark deletes, but the text is still there! What am I doing
wrong? Ed

What else are you doing in your code? What Word version?

All you need is:
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = ""
this will delete the text in the bookmark, and the bookmark itself (once the
text is gone, what is there to bookmark? Nothing!).
You do not need to Select it first.

If it does not, tell us more about your particular situation because it
should.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

Ed

Jean-Guy:
What else are you doing in your code? What Word version?

All you need is:
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = ""
this will delete the text in the bookmark, and the bookmark itself (once the
text is gone, what is there to bookmark? Nothing!).
You do not need to Select it first.

If it does not, tell us more about your particular situation because it
should.

The book mark is to mark my place in a long document, so when I reopen the
doc I can go right to where I left off. The full macro (see below) checks
to see if the bookmark exists: if yes, it selects the bookmark to take me to
that place, then deletes it; if no, it creates the bookmark and puts
highlighted text in it. The bookmark deletes okay, but the text is still
there. I'm using Word 2000.

Ed

Sub LeftOffHere()

If ActiveDocument.Bookmarks.Exists _
("LeftOffHere") = True Then
ActiveDocument.Bookmarks("LeftOffHere").Select
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = ""
ActiveDocument.Bookmarks("LeftOffHere").Delete
Else
ActiveDocument.Bookmarks.Add Name:="LeftOffHere"
ActiveDocument.Bookmarks("LeftOffHere").Range.HighlightColorIndex =
wdBrightGreen
ActiveDocument.Bookmarks("LeftOffHere").Range.Text = "~~**HERE**~~"
End If

End Sub
 
H

Helmut Weber

Hi Ed,

there are two kinds of bookmarks,
lets call them exclusive and inclusive.

Exclusive bookmarks look like !bookmark.text.
Inclusive bookmarks look like [bookmark.text].

Both behave strangely, in a way.

You can assign text to an exclusive bookmark,
ActiveDocument.Bookmarks("Mark1").Range.Text = "xxxx"
however,
msgbox ActiveDocument.Bookmarks("Mark1").Range.Text
returns nothing.

You can assign text to an inclusive bookmark, too,
ActiveDocument.Bookmarks("Mark2").Range.Text = "xxxxx"
however, after that, the bookmark doesn't exist anymore.

There are numerous examples here how to overcome that.

Need more help?


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Ed

Thanks for the info, Helmut. It appears I need to dig a bit deeper into
bookmarks. If I run into trouble, I'll yell!
Ed
 

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