Hi Ram,
In your Message 2 in the Thread, you had mentioned about an alternate
approach to solve the problem
Can you explain further on how to accomplish that? You can use the
same example I have mentioned in the earlier thread.
DOM should be COM (sorry about that), which may make more sense
The "target points" in the document you're creating can be various
things, but most commonly bookmarks are used. When setting up the
template, insert bookmarks instead of merge fields.
In your controlling application, create a data source in memory (using
ADO.NET, for example [with which I'm not familiar, so forgive me if my
sample code looks suspiciously like a mixture of DAO and ADO]
)
The code for the Word stuff would roughly be as follows. I'm assuming
you've already taken care of creating the data source, for which I'll
use rs (recordset)
Microsoft.Office.Interop.Word.Application wrdApp;
Microsoft.Office.Interop.Word.Document wrdDoc;
Microsoft.Office.Interop.Word.Range wrdRng
//Create an instance of Word, and make it invisible
wrdApp = new Microsoft.Office.Interop.Word.Application();
wrdApp.Visible = false;
//Open the template
object strFileName = "C:\\Test\\TestDoc.dot";
object optional = Missing.Value;
wrdDoc = wrdApp.Documents.Add(ref strFileName);
object strBookmarkName = rs.Fields.Item(1).Name
object strData = rs.Fields.Item(1).Value
//We recreate the bookmark around the data so that
//it can be targeted again, if desired
//Note: I usually make this a separate function
If wrdDoc.Bookmarks.Exists(strBookmarkName) Then
wrdRng = wrdDoc.Bookmarks(strBookmarkName).Range
wrdRng.Text = strData
wrdDoc.Bookmarks.Add(strBookmarkName, wrdRng)
End If
wrdDoc.Close(ref blnSave, ref optional, ref optional);
wrdApp.Quit(ref optional, ref optional, ref optional);
****************************************************
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail