473,422 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

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
2 9479
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
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ingvald | last post by:
hi, i've hit a wall regarding php and ms word. what i want is to open a document containing bookmarks, insert text where the bookmarks are, and save. it's working, unless the bookmark is in...
6
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we...
1
by: adam lital | last post by:
Hi, I have word document and i want to replace a specific text with a bookmark using code. Example: in the document i have the text and i want to replace this to a bookmark called ClientName....
0
by: Raj Singh | last post by:
I am facing a problem with Visual C# 2003 and MS Word XP. I am using a customized template for Word and in that template I have defined some bookmarks. I am trying to create a Word document based...
2
by: fordesky | last post by:
Gday, I have a set of Access 2000 tables that I would like to export into a MS Word 2000 template at specific bookmark locations that I've set up. Would anyone know the code to achieve...
1
by: jpr | last post by:
Hello friends, I have a good question for you. I have a form in Access with a check box named chk1. On the same form I have a code that export my data to a template in MS Word. I use bookmark to...
1
by: bluestar | last post by:
hello i am trying to develope an application for word automation.i need to insert header and footer to the document. i found an exampke in msdn and used it in my application.it works well;but...
2
by: Mike Fellows | last post by:
Hi, I am trying to parse a word document to get a list of all the bookmarks that are setup within the document I need to be able to parse the bookmarks though without knowing the bookmark...
0
by: Alan T | last post by:
My code can select the content of a Word document between 2 bookmarks: if (bookmarks.Exists("first bookmark") & bookmarks.Exists("second bookmark")) { object oFirstBookmark = ("first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.