470,831 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

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.Office.Interop.Word.Document myWordDoc = new Document();

myWordDoc.Bookmarks
Nov 2 '06 #1
2 9270
Alan,

In the following code, applicationObject 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 = "BookmarkName";
Word.Range rngRange =
applicationObject.ActiveDocument.Bookmarks.get_Ite m(ref
oBookmarkName).Range;
rngRange.Text = "Text to be inserted and bookmarked";
object oRange = rngRange;
applicationObject.ActiveDocument.Bookmarks.Add("Bo okmarkName", 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 oAnotherBookmarkName = "AnotherBookmarkName";
applicationObject.ActiveDocument.Bookmarks.get_Ite m(ref
oAnotherBookmarkName).Range.Text = "Text to be inserted";

--
Bill Coan
bi******@wordsite.com
"Alan T" <al*************@yahoo.com.auwrote in message
news:OS**************@TK2MSFTNGP02.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.Office.Interop.Word.Document myWordDoc = new Document();

myWordDoc.Bookmarks


Nov 2 '06 #2
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.Content.Select();

Then I need to paste the clipboard into my second document:
WordDoc2.Range rngRange =
applicationObject.ActiveDocument.Bookmarks.get_Ite m(ref
oBookmarkName).Range;
rngRange.Text = // <------ here how do I assign the text from clipboard to
this rngRange object ?

"Bill Coan" <bi******@wordsite.comwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
Alan,

In the following code, applicationObject 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 = "BookmarkName";
Word.Range rngRange =
applicationObject.ActiveDocument.Bookmarks.get_Ite m(ref
oBookmarkName).Range;
rngRange.Text = "Text to be inserted and bookmarked";
object oRange = rngRange;
applicationObject.ActiveDocument.Bookmarks.Add("Bo okmarkName", 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 oAnotherBookmarkName = "AnotherBookmarkName";
applicationObject.ActiveDocument.Bookmarks.get_Ite m(ref
oAnotherBookmarkName).Range.Text = "Text to be inserted";

--
Bill Coan
bi******@wordsite.com
"Alan T" <al*************@yahoo.com.auwrote in message
news:OS**************@TK2MSFTNGP02.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.Office.Interop.Word.Document myWordDoc = new
Document();

myWordDoc.Bookmarks



Nov 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ingvald | last post: by
1 post views Thread by adam lital | last post: by
reply views Thread by Raj Singh | last post: by
1 post views Thread by jpr | last post: by
2 posts views Thread by Mike Fellows | last post: by
reply views Thread by Alan T | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.