Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Attached files open in Reading layout | Page Layout | |||
Question for the WordXP mailmerge - masta's | Mailmerge | |||
Word 2003: Reading Layout changes page numbers in TOC | Page Layout | |||
Reading layout loses table of contents | Microsoft Word Help | |||
reading mac files on a pc | Microsoft Word Help |