By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

Word Bookmark

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.