setting XML elements in Word doc to text

F

Frank Rice

Hi,
From VSTO in Visual Studio.NET, I open a Word doc based on a template. In
the template I have attached a schema and added some elements to the doc,
one of which is called "FirstName.". What I am trying to do is set the value
of the FirstName element to some text. I have tried several techniques such
as

dim wdApp as New Word.Application
dim wdDoc as New Word.Document
dim wdTemp = "C:\MyTemplate.dot"
dim wdNode as Word.XMLNode

wdDoc = wdApp.Documents.Add(wdTemp)

wdNode = wdDoc.SelectSingleNode("/FirstName")
wdNode.Text = "Nancy"

when I do this, I get error msg 'object reference not set to an instance of
an object" telling me that '/FirstName" is not a valid XPath, I think. I
then try

wdNode = wdDoc.SelectSingleNode("FirstName")
wdNode = "Nancy"

and get the same error.

My question is how can I set the value of an XML element in a doc to a text
value at run time? Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top