471,594 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Copy text between 2 bookmarks

I have two bookmarks,
eg. beginMark and endMark

I need to get the text between these 2 bookmarks, how do I do that?

eg.

<beginMark>
Hello Word!
This is Saturday.
Now is Sunday.
<endMark>
Nov 5 '06 #1
2 3784
I need to get the text between these 2 bookmarks, how do I do that?

Word.Document docActive = applicationObject.ActiveDocument;
object oFirstBookmark = "FirstBookmark";
Word.Range rngFirstBookmark =
docActive.Bookmarks.get_Item(ref oFirstBookmark).Range;
object oSecondBookmark = "SecondBookmark";
Word.Range rngSecondBookmark =
docActive.Bookmarks.get_Item(ref oSecondBookmark).Range;
object firstBookmarkEnd = rngFirstBookmark.End;
object secondBookmarkStart = rngSecondBookmark.Start;
Word.Range rngTarget =
docActive.Range(ref firstBookmarkEnd, ref secondBookmarkStart);
string DesiredText = rngTarget.Text;

--
Bill Coan
bi******@wordsite.com
920-779-9148
"Alan T" <al*************@yahoo.com.auwrote in message
news:u8**************@TK2MSFTNGP04.phx.gbl...
>I have two bookmarks,
eg. beginMark and endMark

I need to get the text between these 2 bookmarks, how do I do that?

eg.

<beginMark>
Hello Word!
This is Saturday.
Now is Sunday.
<endMark>

Nov 5 '06 #2
Thanks.
I have 2 questions about that:
1) I need to put the text or content between 2 bookmarks into a bookmark in
another document.

Word.Range rngTarget = docActive.Range(ref firstBookmarkEnd, ref
secondBookmarkStart);
object oThirdBookmark = "Bookmark3";
Word.Range rngThirdBookmark = doc3.Bookmarks.get_Item(ref
oThirdBookmark).Range;
How do I tell to insert the content at that bookmark in my second document ?

2) Do you think Copy and Paste is good ?

"Bill Coan" <bi******@wordsite.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I need to get the text between these 2 bookmarks, how do I do that?

Word.Document docActive = applicationObject.ActiveDocument;
object oFirstBookmark = "FirstBookmark";
Word.Range rngFirstBookmark =
docActive.Bookmarks.get_Item(ref oFirstBookmark).Range;
object oSecondBookmark = "SecondBookmark";
Word.Range rngSecondBookmark =
docActive.Bookmarks.get_Item(ref oSecondBookmark).Range;
object firstBookmarkEnd = rngFirstBookmark.End;
object secondBookmarkStart = rngSecondBookmark.Start;
Word.Range rngTarget =
docActive.Range(ref firstBookmarkEnd, ref secondBookmarkStart);
string DesiredText = rngTarget.Text;

--
Bill Coan
bi******@wordsite.com
920-779-9148
"Alan T" <al*************@yahoo.com.auwrote in message
news:u8**************@TK2MSFTNGP04.phx.gbl...
>>I have two bookmarks,
eg. beginMark and endMark

I need to get the text between these 2 bookmarks, how do I do that?

eg.

<beginMark>
Hello Word!
This is Saturday.
Now is Sunday.
<endMark>


Nov 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ingvald | last post: by
2 posts views Thread by Jay | last post: by
reply views Thread by Mark Hayworth | last post: by
15 posts views Thread by Francach | last post: by
1 post views Thread by JosAH | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.