473,413 Members | 1,679 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,413 software developers and data experts.

Word automation

Hi
I have a word document(template) with some BookMarks. Also for the first time I have inserted some text against those bookmarks in the document through my code and have saved the document. For the next time I need to open the saved document with the text in bookmarks and before opening I may need to overwrite with the fresh values on some of the bookmarks.
When I tried to do this using Range.text or Range.InsertAfter methods it always appends with the existing text
Where as I want to replace the old text with the new one for that bookmark
Please let me know what is the solution for this

Regards
Nov 18 '05 #1
2 1447
Hi Veda
This should help for your problem

http://msdn.microsoft.com/library/de...ookmarktext.as

Regards
Ramaprasad Upadhyay
MCSD | Microsoft .NET MVP | MS India Community Star
Nov 18 '05 #2
Hi Veda
Here is test code i have implemented

==================================================

private Microsoft.Office.Interop.Word.Application app = null

private void button1_Click_1(object sender, System.EventArgs e

app = new Microsoft.Office.Interop.Word.Application()
object optional = Missing.Value
object fileName = @"D:\Ramaprasad\Temp.rtf";

app.Documents.Open(ref fileName, ref optional,ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional)
MessageBox.Show("Opened")

BookMarkReplaceRange("Page1", "ramprasad")

app.ActiveDocument.Save()

app.Quit(ref optional,ref optional,ref optional)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(app)
app = null
internal void BookMarkReplaceRange(string bookmarkName, string newText)
{
object missingValue = Type.Missing;
object oBookmarkName = bookmarkName;
Microsoft.Office.Interop.Word.Range rng = app.ActiveDocument.Bookmarks.get_Item(ref oBookmarkName).Range;
rng.Text = newText;
object oRng = rng;
app.ActiveDocument.Bookmarks.Add(bookmarkName, ref oRng);
}
Nov 18 '05 #3

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

Similar topics

1
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
2
by: kids | last post by:
Does anybody know any reason which could cause Ms. word automation to crash? I try to call word automation to open a document and use find and replace function. For some reason it works but I...
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
2
by: Radek | last post by:
Hi, I have got such problem: in my directory "C:\folder" I have 3 files in MS WORD (having tables, images etc), these are: "1.doc", "2.doc", "3.doc". I want to write an application (C# of...
4
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
5
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be...
10
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.