Copy text between 2 bookmarks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    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>


  • Bill Coan

    #2
    Re: Copy text between 2 bookmarks

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

    Word.Document docActive = applicationObje ct.ActiveDocume nt;
    object oFirstBookmark = "FirstBookmark" ;
    Word.Range rngFirstBookmar k =
    docActive.Bookm arks.get_Item(r ef oFirstBookmark) .Range;
    object oSecondBookmark = "SecondBookmark ";
    Word.Range rngSecondBookma rk =
    docActive.Bookm arks.get_Item(r ef oSecondBookmark ).Range;
    object firstBookmarkEn d = rngFirstBookmar k.End;
    object secondBookmarkS tart = rngSecondBookma rk.Start;
    Word.Range rngTarget =
    docActive.Range (ref firstBookmarkEn d, ref secondBookmarkS tart);
    string DesiredText = rngTarget.Text;

    --
    Bill Coan
    billcoan@wordsi te.com
    920-779-9148
    "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
    news:u8asMLKAHH A.4864@TK2MSFTN GP04.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>
    >

    Comment

    • Alan T

      #3
      Re: Copy text between 2 bookmarks

      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 firstBookmarkEn d, ref
      secondBookmarkS tart);
      object oThirdBookmark = "Bookmark3" ;
      Word.Range rngThirdBookmar k = 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" <billcoan@words ite.comwrote in message
      news:%23kzz5bNA HHA.2276@TK2MSF TNGP03.phx.gbl. ..
      >I need to get the text between these 2 bookmarks, how do I do that?
      >
      Word.Document docActive = applicationObje ct.ActiveDocume nt;
      object oFirstBookmark = "FirstBookmark" ;
      Word.Range rngFirstBookmar k =
      docActive.Bookm arks.get_Item(r ef oFirstBookmark) .Range;
      object oSecondBookmark = "SecondBookmark ";
      Word.Range rngSecondBookma rk =
      docActive.Bookm arks.get_Item(r ef oSecondBookmark ).Range;
      object firstBookmarkEn d = rngFirstBookmar k.End;
      object secondBookmarkS tart = rngSecondBookma rk.Start;
      Word.Range rngTarget =
      docActive.Range (ref firstBookmarkEn d, ref secondBookmarkS tart);
      string DesiredText = rngTarget.Text;
      >
      --
      Bill Coan
      billcoan@wordsi te.com
      920-779-9148
      "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
      news:u8asMLKAHH A.4864@TK2MSFTN GP04.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>
      >>
      >
      >

      Comment

      Working...