Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

How to get bookmark text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Word.user - 13 Aug 2007 05:28 GMT
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
Russ - 13 Aug 2007 08:52 GMT
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

> I have a bookmark start, I want to get text, and length of that text next to
> it.
[quoted text clipped - 10 lines]
>
> Thanks in advance

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Helmut Weber - 13 Aug 2007 14:36 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Klaus Linke - 13 Aug 2007 17:55 GMT
If the empty bookmark is right next to some word, you could get that word
with
ActiveDocument.Bookmarks("Mark").Range.Words(1)

Regards,
Klaus

> Hi,
>
[quoted text clipped - 13 lines]
> see:
> http://word.mvps.org/faqs/macrosvba/workwithbookmarkscontent.htm
Helmut Weber - 13 Aug 2007 23:45 GMT
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?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Klaus Linke - 13 Aug 2007 23:49 GMT
> 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
Word.user - 14 Aug 2007 02:12 GMT
Hi,
Thanks for your input.

This is what I have:
IStart Bookmark Begins Here

What I want is
[Start Bookmark Begins Here]

> Hi Klaus,
>
[quoted text clipped - 11 lines]
>
> What would your translation be?
Klaus Linke - 14 Aug 2007 02:30 GMT
> Hi,
> Thanks for your input.
[quoted text clipped - 4 lines]
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.