Inserting Data into a Template

M

Magnus.Moraberg

Hi,

I have a template word document into which I wish to insert
information. At the start of the template, I have -

Name:

And I wish to insert here a persons name via C#, for example -

Name: Barry

To do this, I in fact have the following -

Name: USER_NAME

and I use the Replace function to replace USER_NAME with Barry, or
whoever the file pertains to.

But I'm thinking there is another way of doing this,

Thanks,

Barry.
 
D

Doug Robbins - Word MVP

In the template, replace USER_NAME with { DOCVARIABLE varUserName }field

Then have your code assign the user name to the document variable
varUserName and have it update the fields in the document

With ActiveDocument
.Variables("varUserName").Value = "Barry"
'set values of other variables
.Range.Fields.Update
End With

would be the code to use if you were using VBA - sorry I can't help with the
equivalent C#

Note that when inserting the fields in the template, you must use Ctrl+F9 to
insert each pair of field delimiters {}

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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