Link to home
Start Free TrialLog in
Avatar of Danny Kon
Danny KonFlag for Netherlands

asked on

send outout from a batch file to MS-word

I have a batch file what checks some values in a text file.
I want to put the results direct to a MSWord doc
If this can be done I also like  to know if its possible to send this output to a specific place in this Document (Using a template)

Operating system: XP
Office 2002

Thx Dan  
Avatar of DrWarezz
DrWarezz

As far as I know, there's not a way of editing an MS WORD document.. There's probably some utilies that can do something like this, but I'm sure it can't be done without external software.

I personally don't know any utilities to do this, hopefully someone else round here does..

Do you know how to create a Macro? If so, you can call a macro via DOS. :o\

gL,
[r.D]
You can format the whole thing in a txt file, then open it in Word, something like:

>file.txt echo.
>>file.txt echo    Heading: this is the report for %DATE%
>>file.txt echo.
>>file.txt echo.
>>file.txt echo.  Data follows
>>file.txt echo.

>>file.txt  CALL  batch_file_what_checks_some_values.bat  /Switches_for_Batch  "input path\filename if batch needs it.txt"

>>file.txt echo.
>>file.txt echo.
>>file.txt echo    Footer: this report ran by %USERNAME%
>>file.txt echo.

Start "Title: Please save the file"  "%ProgramFiles%\Microsoft Office\Office10\winword"  "file.txt"

:: end of batch or cleanup temp files or move word doc,  whatever.



If the document is already formatted, you could use use vbscript to access Word methods that are exposed to Windows, including search to find the place holder, and paste or insert to retrieve the clipboard or text file.  This way you could also do the saving straight from the vbscript with no user help.
 
Avatar of Danny Kon

ASKER

K_2K

Looks good but the last answer about the VBscript at a pre formated doc how to do this

Say i have a document saying something like:

To whom it may concern,

texttexttexttexttexttexttexttexttexttexttexttext

ANSWER ONE HERE ________

texttexttexttexttexttexttext

ANSWER TWO HERE _________

Greetings


and the the batch file has an output something like:

answer one = bla
answer two = blabla

Thanks Dan
What exactly are you trying to do here?
Create some sort of test? Please elaborate; because if you're trying to do what I think you're trying to do, then there's much easier ways round this.

[r.D]
Avatar of Joseph O'Loughlin
Hi dannykon,
Have your batch file output to a text file.  
In a different file with the doc extention use <Ctrl>F9 and then INCLUDETEXT "Filename" - see online help.
If more complex formatting is needed I'd suggest txt2rtf convertion utilities.
usual disclaimers apply
DrWarezz,

I have a temporary assignment at a big company in the Netherlands
Some People at this assignment are testing software and the use SMS for this
To test the software the use msiexec and than they start/install to test if the installation is correct
The company require this testing has a standard Word template what has to be used and filled in
Yesterday i found an extra option on the msiexec where you can make a log and this log is telling exacly
what is happening.
This log is for the people who test the platform very hard to read so what i did is that i make a batch file with help from here offcourse what gives the needed info.
Now the problem is that management of this company want to have the output to the same document as what they used when testing this by hand also an simulair document can be used.

further info needed please tell me
Thanks in advance
Dan
Okay..

you said:
"Say i have a document saying something like:

To whom it may concern,

texttexttexttexttexttexttexttexttexttexttexttext

ANSWER ONE HERE ________

texttexttexttexttexttexttext

ANSWER TWO HERE _________

Greetings


and the the batch file has an output something like:

answer one = bla
answer two = blabla"

This document that you refer to above, is it a microsoft word document? or just a .txt ?

If it's just a .txt, then I can help you code something to extract particular data from it, then output it to a word document (using K_2K's method :)).

[r.D]
That's the problem this is a Word document with macro's and a specific layout so I think the best way to go is to
execute the batch from a macro in the word document but I have very little knowhow from VB.
I can manage to write a little VB code to execute the batch but than how to import the information in Word on the specific places
I know it can be done but need a VB expert

Help will be very much appriciated

Dan

ASKER CERTIFIED SOLUTION
Avatar of K_2K
K_2K

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
K_2K

Funny and good solution I had only one problem that MSword had different language setting.
Its working ok but i am a little scared that if a lot of programs are open or if the computer just have a bad day :) that
the program will give problems but till now perfect job

THX

Dan
Thanks,  and your welcome, glad to help.


Yes,  there were a lot of problems with many programs open and an impatient guy (me) trying to do other work during these types of scripts the first time i wrote one like it.  Dont let that deter you from copying everything before the ' START to a new name and writing your own if you have a similar need.

The key is in the propper and often use of the waitfor(x) routine.  
A simple sleep would wait a while and then send a key to any program that might have been clicked or otherwize taken "focus" as the system sees it, causing wrong things to happen.
The waitfor(x), when applied after any sleeps or to wait for a new dialog box to appear, will constantly attempt to take focus of the window with a matching title starting with x.  If the window does not exist this will fail, sleep a bit, and try again.  The rest of the script is frozen there until focus on that window can happen.  Only then is control returned to the line after that waitfor(x) and keys can be sent knowing that window is ready to get them.

(\o/)  Happy Hunt and Pecking,
2K