How to get bookmark text

W

Word.user

I have a bookmark start, I want to get text, and length of that text next to
it.
When I use
Selection.GoTo What:=wdGoToBookmark, Name:="start"
Set bmrange = Selection.Range
MsgBox (bmrange.Text)

The msgbox shows nothing. This is what the bookmark looks like
IBookmark text

I want to retrieve "Bookmark text" and no of words and length of "Bookmark
text"

Thanks in advance
 
R

Russ

Word,
After going and selecting
Msgbox Selection.Text
Or
Without going and selecting
ActiveDocument.Bookmarks("start").Range.Text
ActiveDocument.Bookmarks("start").Range.Words.Count
ActiveDocument.Bookmarks("start").Range.Characters.Count
 
H

Helmut Weber

Hi,
This is what the bookmark looks like
IBookmark text

which is a "placeholder" bookmark
as opposed to an enclosing [bookmark].

The first does not hold any text at all,
though you can assign text to it...

' for a placeholder bookmark
ActiveDocument.Bookmarks("Mark1").Range.Text = "xxx"
MsgBox ActiveDocument.Bookmarks("Mark1").Range.Text ' nothing

see:
http://word.mvps.org/faqs/macrosvba/workwithbookmarkscontent.htm

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Klaus Linke

If the empty bookmark is right next to some word, you could get that word
with
ActiveDocument.Bookmarks("Mark").Range.Words(1)

Regards,
Klaus


Helmut Weber said:
Hi,
This is what the bookmark looks like
IBookmark text

which is a "placeholder" bookmark
as opposed to an enclosing [bookmark].

The first does not hold any text at all,
though you can assign text to it...

' for a placeholder bookmark
ActiveDocument.Bookmarks("Mark1").Range.Text = "xxx"
MsgBox ActiveDocument.Bookmarks("Mark1").Range.Text ' nothing

see:
http://word.mvps.org/faqs/macrosvba/workwithbookmarkscontent.htm

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Hi Klaus,
If the empty bookmark is right next to some word,
you could get that word with
ActiveDocument.Bookmarks("Mark").Range.Words(1)

good to know.

Even if the bookmark is within a word,
and also sentences(1), sections(1), paragraphs(1).

One could need it some day.
(Könnte man noch mal brauchen).

What would your translation be?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Klaus Linke

One could need it some day.
(Könnte man noch mal brauchen).

What would your translation be?

Might come in handy? Though my school English isn't any better than yours I
think <g>

Klaus
 
W

Word.user

Hi,
Thanks for your input.

This is what I have:
IStart Bookmark Begins Here

What I want is
[Start Bookmark Begins Here]
 
K

Klaus Linke

Word.user said:
Hi,
Thanks for your input.

This is what I have:
IStart Bookmark Begins Here

What I want is
[Start Bookmark Begins Here]



Making use of Helmut's extension, if you want the bookmark to span the
current sentence:

ActiveDocument.Bookmarks.Add _
Name:="start", _
Range:=ActiveDocument.Bookmarks("start").Range.Sentences(1)

or

With ActiveDocument
.Bookmarks.Add _
Name:="Test", _
Range:=.Bookmarks("Test").Range.Paragraphs(1).Range
End With

if it should span the whole paragraph.


In effect, you need to put in a new bookmark with the same name, destroying
the old one in the process.

Greetings,
Klaus
 

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