Word Bookmark

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

    Word Bookmark

    How do I make use of the Bookmarks property so that I can write a text
    at/below the position of a particular bookmark or the first bookmark ?

    private Microsoft.Offic e.Interop.Word. Document myWordDoc = new Document();

    myWordDoc.Bookm arks


  • Bill Coan

    #2
    Re: Word Bookmark

    Alan,

    In the following code, applicationObje ct refers to the Word application. The
    code targets the application's ActiveDocument, but you can easily modify
    this to target the document referenced by myWordDoc.

    The following code inserts some text at a bookmark and then reapplies the
    bookmark, in case you need work with the same bookmark later on.

    object oBookmarkName = "BookmarkNa me";
    Word.Range rngRange =
    applicationObje ct.ActiveDocume nt.Bookmarks.ge t_Item(ref
    oBookmarkName). Range;
    rngRange.Text = "Text to be inserted and bookmarked";
    object oRange = rngRange;
    applicationObje ct.ActiveDocume nt.Bookmarks.Ad d("BookmarkName ", ref oRange);

    The following code simply inserts some text at a bookmark. In the process,
    the bookmark will be deleted, unless it contained no text to start with, in
    which case it will still exist but the inserted text will fall after the
    bookmark, not within it.

    object oAnotherBookmar kName = "AnotherBookmar kName";
    applicationObje ct.ActiveDocume nt.Bookmarks.ge t_Item(ref
    oAnotherBookmar kName).Range.Te xt = "Text to be inserted";

    --
    Bill Coan
    billcoan@wordsi te.com
    "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
    news:OS2uoyi$GH A.5068@TK2MSFTN GP02.phx.gbl...
    How do I make use of the Bookmarks property so that I can write a text
    at/below the position of a particular bookmark or the first bookmark ?
    >
    private Microsoft.Offic e.Interop.Word. Document myWordDoc = new Document();
    >
    myWordDoc.Bookm arks
    >
    >

    Comment

    • Alan T

      #3
      Re: Word Bookmark

      Hi Bill,

      Thanks for your code.
      In your example code they are using the predefined string, however in my
      case, I will need to insert the text from the clipboard.

      I copied the content of first Word document into clipboard:
      WordDoc1.Conten t.Select();

      Then I need to paste the clipboard into my second document:
      WordDoc2.Range rngRange =
      applicationObje ct.ActiveDocume nt.Bookmarks.ge t_Item(ref
      oBookmarkName). Range;
      rngRange.Text = // <------ here how do I assign the text from clipboard to
      this rngRange object ?



      "Bill Coan" <billcoan@words ite.comwrote in message
      news:e6SZwoo$GH A.1224@TK2MSFTN GP04.phx.gbl...
      Alan,
      >
      In the following code, applicationObje ct refers to the Word application.
      The code targets the application's ActiveDocument, but you can easily
      modify this to target the document referenced by myWordDoc.
      >
      The following code inserts some text at a bookmark and then reapplies the
      bookmark, in case you need work with the same bookmark later on.
      >
      object oBookmarkName = "BookmarkNa me";
      Word.Range rngRange =
      applicationObje ct.ActiveDocume nt.Bookmarks.ge t_Item(ref
      oBookmarkName). Range;
      rngRange.Text = "Text to be inserted and bookmarked";
      object oRange = rngRange;
      applicationObje ct.ActiveDocume nt.Bookmarks.Ad d("BookmarkName ", ref
      oRange);
      >
      The following code simply inserts some text at a bookmark. In the process,
      the bookmark will be deleted, unless it contained no text to start with,
      in which case it will still exist but the inserted text will fall after
      the bookmark, not within it.
      >
      object oAnotherBookmar kName = "AnotherBookmar kName";
      applicationObje ct.ActiveDocume nt.Bookmarks.ge t_Item(ref
      oAnotherBookmar kName).Range.Te xt = "Text to be inserted";
      >
      --
      Bill Coan
      billcoan@wordsi te.com
      "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
      news:OS2uoyi$GH A.5068@TK2MSFTN GP02.phx.gbl...
      >How do I make use of the Bookmarks property so that I can write a text
      >at/below the position of a particular bookmark or the first bookmark ?
      >>
      >private Microsoft.Offic e.Interop.Word. Document myWordDoc = new
      >Document();
      >>
      >myWordDoc.Book marks
      >>
      >>
      >
      >

      Comment

      Working...