View Single Post
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Rhino
 
Posts: n/a
Default Newbie question: Reading external files

Can a Word macro do a find in an external file?

I'm new to Word macros and, to tell the truth, I haven't done much with
macros in _any_ language. However, I have been programming for 20+ years in
a variety of languages, especially COBOL and Java, so I'm quite familiar
with programming in general.

I'm running Word 2002 and I would like to write a macro that reads an
external text file, finds specific data in that file, and then writes it to
the Word document. For example, let's say the external file is organized
like this, with each line containing a key, an equals sign, and a value:


Name=Rhino
Target=Programmer
Address=123 Main Street, Anytown, Ontario, Canada


I want my macro to be able to find the value associated with any given key.
[Then, the other code in the macro will format that value appropriately; for
example, the value of the Name might be centered on the first line and be
Arial Bold 24 while the value of the Target might be left-justified Arial
12, and so on.]

Is it possible for my macro to do finds on specific keys within an external
file? In looking at the macro help:
- I don't see anything that suggests this is possible for File or TextStream
objects
- I don't see anything in the 'find' article that suggests that 'find' can
read external files

If it is possible, could someone possibly point me to a brief example
illustrating the technique? If it is not possible, can anyone suggest
something that might be "close enough" for my purposes?

Basically, I'm trying to make sure that a given Word document (or group of
documents) gets its information from a single formatted external text file.
It would make my life a lot easier if I could organize that external file in
a way that makes it easy to get selected parts of the file _directly_. (I
realize that I can just read the external file a line at a time and just
wait for the specific lines I want but I'd rather have direct access than
having to do all of this via sequential reads.)

Also, if anyone can point me to the best online resources for Word macros,
I'd appreciate it. The Help is not that bad but it would be nice to be able
to supplement it with other resources.

--
Rhino