Importing/parsing data from an external file in Word 2007 Macros

J

JediKaiti

Hello! I am wondering if this is possible, and if so, how do I do it?

What I want to do is this:

I have a template, and I want to write a macro that will create a document
based on this template by pulling data out of other files, formatting the
data, and putting it in the appropriate section of the document.

I have no experience with Word Macros or VBA, although I have programmed in
VB.NET in the past.

Any suggestions would be helpful!

Thank you!

Kaiti
 
G

Greg Maxey

You would need an AutoNew macro in the template that contained the code
statements.

Sub AutoNew()
ActiveDocument.Bookmarks("DIP1").Range.InsertFile FileName:="C:\Test.doc"
End Sub

Where DIP1 is the first data insertion point and "C\Test.doc" is the file
that you want inserted at that point.
 
J

JediKaiti

Thanks, Greg, that is very helpful!

Next question: the data I'm pulling in from an external file is not in the
format I want to use in the document. It actually looks more like this:

%Verbs = (
"arm" => {
description => "
A prerequisite command for a potentially
hazardous
command.
",
discrete => 1,
},
"close" => {
description => "
Mechanically close a device controlled by the
command
element. \\emph{close} works in conjunction
with the
\\emph{open} verb.
",
discrete => 1,
},

And I want to turn it into a table with 3 columns: name (i.e. "arm" or
"close"), description, and discrete.

I am guessing that I could just import the external file into a string, and
parse out the string? Would that be the way to go, here? And how do I do that?

Thanks again!

Kaiti
 

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