TechWhirl (TECHWR-L) is a resource for technical writing and technical communications professionals of all experience levels and in all industries to share their experiences and acquire information.
For two decades, technical communicators have turned to TechWhirl to ask and answer questions about the always-changing world of technical communications, such as tools, skills, career paths, methodologies, and emerging industries. The TechWhirl Archives and magazine, created for, by and about technical writers, offer a wealth of knowledge to everyone with an interest in any aspect of technical communications.
Updating Word tables from a .txt source file using VBA (or some other method).
Subject:Updating Word tables from a .txt source file using VBA (or some other method). From:"bja" <bashley -at- preston -dot- net> To:"TECHWR-L" <techwr-l -at- lists -dot- raycomm -dot- com> Date:Mon, 15 Sep 2003 12:58:59 +1000
Hi everyone.
This is one for the VBA'ers out there. I'm also cross-posting so please
forgive any overlap.
Having spent the last four hours unsuccessfully trying to nut out a solution
(I've spent two hours on-line trying to find an answer without success and
have tried a number of merging/conversion strategies that failed miserably),
time issues now forces me to throw this to the group in the hope that
someone more proficient in VBA etc can offer some assistance.
I have a .txt file called, say, STAFF.TXT that looks as follows:
File: STAFF.TXT
Date: 15/09/2003
Title: Output to a text file
*****************************
******** Columns *********
*****************************
Table Field Value Type
----------------------------------------------------------------------------
-
NAME_AGE S_Name YN Alpha
F_Name YN Alpha
Age YN Num
ADDRESS Address1 YN Alpha/Num
Address2 YN Alpha/Num
Previously, someone set up a Word file where each block of information (ie
NAME_AGE, ADDRESS, ETC - in the above example) was manually placed into
separate tables along with addition information.
The trouble is that the source file is updated regularly so the final Word
document also needs updating each time (in the real document, there are some
230 tables).
I'm mostly FrameMaker these days but the boss has asked me to help him find
a solution
What I'm hoping for is a Word 2000 solution using VBA. I'm hoping VBA can
interrogate the source document and somehow identify each item in the
'Table' column as these form the headings of each table in the Word document
(I'm hoping it can use an empty row as a separator) .
I then need it to identify that the items in the 'Field' and subsequent
columns 'belong' to the items in the 'Table' column and then output these to
the Word document, replacing the existing data in each relevant table cell.
I know that Word can do much of this when converting text to tables but
there are only single spaces between two of the columns on occasion and it
also needs to exclude repeated '====' and I'd like it to source the
information from the text file directly.
The task is as follows:
EXISTING WORD FILE
Table 1:
NAME_AGE
Fields Type Extra Field 1 Extra Field 2
----------------------------------------------------------------------------
---------------------------
S_Name Alpha Black ABCD
Age Num Black -
----------------------------------------------------------------------------
---------------------------
Table 2:
ADDRESS
Fields Type Extra Field 1 Extra Field 2
----------------------------------------------------------------------------
---------------------------
Address1 Alpha/Num Black A-K
Address2 Alpha/Num Blue -
----------------------------------------------------------------------------
---------------------------
Table 3:
ETC.....
NEW STAFF.TXT generated (as shown above) that now includes a field called
F_Name in the NAME_AGE table and with a 'Type' change in the ADDRESS table.
VBA then needs to look at STAFF.TXT, recognise the parts of the file, remove
empty spaces and then overwrite the existing information in the EXISTING
WORD FILE to create a new Word file as follows:
NEW WORD FILE.doc
Table 1:
NAME_AGE
Fields Value Type Extra Field 1 Extra
Field 2
----------------------------------------------------------------------------
---------------------------
S_Name YN Alpha Black ABCD
F_Name YN Alpha Black -
Age YN Num Black -
----------------------------------------------------------------------------
---------------------------
Table 2:
ADDRESS
Fields Value Type Extra Field 1 Extra
Field 2
----------------------------------------------------------------------------
---------------------------
Address1 YN Alpha Black A-K
Address2 YN Alpha/Num Blue -
----------------------------------------------------------------------------
---------------------------
Table 3:
ETC.....
Note that the Extra Field 1 and Extra Field 2 data is untouched.
Any help would be greatly appreciated (I hope I've presented the problem
clearly enough).
I'm using Windows98/Word2000.
TIA.
Regards,
Bruce Ashley
Senior Technical Writer
----------------------------------------------------------------------------
-----------------------------------
Preston Aviation Solutions Pty Ltd Website: http://www.preston.net
488 Victoria Street email: bashley -at- preston -dot- net
Richmond VIC 3121 Ph: +61 3 9429 2266
Australia Fax: +61 3 9429 8284
----------------------------------------------------------------------------
-----------------------------------
Setting the standard in software solutions for the global aviation industry,
utilising advanced simulation, scheduling, optimisation and visualisation
technology.
A subsidiary of The Boeing Company
NEED TO PUBLISH YOUR FRAMEMAKER CONTENT ONLINE?
?Mustang? (code name) is a NEW online publishing tool for FrameMaker that
lets you easily single-source content to Web, intranets, and online Help.
The interface is designed for FrameMaker users, so there is little or no
learning curve and no macro language required! See a live demo that
will take your breath away: http://www.ehelp.com/techwr-l3
---
You are currently subscribed to techwr-l as:
archive -at- raycomm -dot- com
To unsubscribe send a blank email to leave-techwr-l-obscured -at- lists -dot- raycomm -dot- com
Send administrative questions to ejray -at- raycomm -dot- com -dot- Visit http://www.raycomm.com/techwhirl/ for more resources and info.