Reply
 
Thread Tools Display Modes
  #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


  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill
 
Posts: n/a
Default Newbie question: Reading external files

This NG is for end users; you're much more likely to get VBA help if you
post in microsoft.public.word.vba.beginners

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Rhino" wrote in message
...
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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Attached files open in Reading layout monrored Page Layout 1 April 28th 05 02:45 AM
Question for the WordXP mailmerge - masta's Jürgen Germonpré Mailmerge 1 March 4th 05 01:12 PM
Word 2003: Reading Layout changes page numbers in TOC [email protected] Page Layout 3 January 11th 05 02:46 AM
Reading layout loses table of contents ASwadener Microsoft Word Help 14 January 10th 05 04:40 PM
reading mac files on a pc jinty Microsoft Word Help 2 December 12th 04 08:09 PM


All times are GMT +1. The time now is 07:45 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"