Copy text between 2 bookmarks

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

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>
 
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;
 
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 ?
 
Back
Top