How to collect data into table of Word template using VBA

S

Sam

I want to collect data info from XML file into the specific cell of one table
in Word template. I want to know whether it is possible to use VBA implement
this function. Or are there any other methods?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2Ft?=,
I want to collect data info from XML file into the specific cell of one table
in Word template. I want to know whether it is possible to use VBA implement
this function. Or are there any other methods?
VBA can do this, but in order to parse the XML as XML you'll need to use an
external XML parcer to the VBA project. This can be done by using late-binding
or early-binding. Early-binding is simpler to program against because you get
Intellisense, but it means your project has to have a valid Reference to the
object library. For example:

Go through Tools/References and put a check mark next to Microsoft XML v5.0, for
example.

Otherwise, VBA provides the general Open, Write, etc. commands for handling pure
text files. You could get that to work, but it wouldn't be as "elegant".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
S

Sam

Thank you for your answer!

If I want to load data info from pure txt file into specific cell of one
table in Word document, what kind of method should I use? Could you give me
some simple code sample?

For example, I have a 'txt' file, with some contact info(Incluing
name,telephone number, address,Email...)

I want to use those contact info to fill one table(which have two columns,
name and email) in word document. In the table, it only give the name info,
we should fill the email column by ourself. How can we collect info from the
'txt' file? it is possible to use VBA to fill the email info automatively?
Could you give me some hints?

Regards

Sam
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2Ft?=,
If I want to load data info from pure txt file into specific cell of one
table in Word document, what kind of method should I use? Could you give me
some simple code sample?

For example, I have a 'txt' file, with some contact info(Incluing
name,telephone number, address,Email...)

I want to use those contact info to fill one table(which have two columns,
name and email) in word document. In the table, it only give the name info,
we should fill the email column by ourself. How can we collect info from the
'txt' file? it is possible to use VBA to fill the email info automatively?
Could you give me some hints?
It's really impossible to even begin to think about this without knowing how
the XML is structured. Probably, I'd "walk" the text file line-by-line and use
Instr to check whether the line contains the "Name". If it does, then I'd move
down the required number of lines to the Email address, if the text file is
structured so that this would be possible.

If everything is on one line, which would be quite possible with XML, then you
might have to read character-by-character, comparing the result to a particular
string (such as the XML tag and the name), then continue until you get the
email XML tag, then start accumulating the characters within that tag until you
hit the end-tag.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 

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