Well, I found out how it works. It was in a google.newsgroup. Somebody found out how to make the arguments for printout work. (I would like to know HOW this guy found out how it's done)
I give the code here because I am sure a lot of people struggle with this COM-thing.
What I do in this program is read a wordfile that is intended to send to a customer along with his order. There is a message for that customer and there are 7 empty Formfields in it.
This program fills the formfields from a coldfusionform and puts the order-nr in the footer of the word-document. After that the File is saved as a PRN-File because it will be printed elsewhere on a computer where Word isn't installed.
The order-pick-program prints the document in dos (See below) and the order-picker can tell to which order it belongs because of
the ordernr in the footer.
I know it's a very special problem, but perhaps somebody could use this example.
<cfset adresdaten = ''>
<cfset adresdaten = listappend(adresdaten,'Anrede')>
<cfset adresdaten = listappend(adresdaten,'name')>
<cfset adresdaten = listappend(adresdaten,'Abteilung')>
<cfset adresdaten = listappend(adresdaten,'Strasse und Hausnummer')>
<cfset adresdaten = listappend(adresdaten,'NL')>
<cfset adresdaten = listappend(adresdaten,'PLZ')>
<cfset adresdaten = listappend(adresdaten,'Ort')>
<cfset adresdaten = listappend(adresdaten,'xx')>
<cfset adresdaten = listappend(adresdaten,'xx')>
<cfset namedoc = "b2">
<cfset auftrag = "MI131148">
<!--- Try to connect to the Word application object --->
<cftry>
<!--- If it exists, connect to it --->
<cfobject
action="CONNECT"
class="Word.Application"
name="objWord"
type="COM">
<cfcatch>
<!--- The object doesn't exist, so create it --->
<cftry>
<cfobject
action="CREATE"
class="Word.Application"
name="objWord"
type="COM">
<!--- Word isn't installed, or ColdFusion doesn't have access to it --->
<cfcatch type="Object">
<font color="RED">Cannot create Word Object<br>
Make sure Word is installed and that ColdFusion has permissions to
use the Word COM objects.</font>
<cfabort>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
<!--- formfelder füllen start 7 stück --->
<cfset objWord.Visible = false>
<cfset objDoc = objWord.Documents>
<cfset newDoc = objDoc.Open("c:\inetpub\
<cfset theFields = newDoc.FormFields>
<cfset a = 0>
<CFLOOP COLLECTION="#theFields#" ITEM="this">
<cfset a = a + 1>
<cfif a lt 8>
<cfset this.Result = listgetat(adresdaten,a)>
</cfif>
<CFOUTPUT>
#this.Name#<BR>
#this.Result#<P>
</CFOUTPUT>
</CFLOOP>
<!--- füllen footer mit auftrag-nr --->
<CFSCRIPT>
/* Get the doc */
objDocs = objWord.Documents;
objDoc = objDocs.Open("c:\inetpub\
/* Get the Sections collection */
objSecs = objDoc.Sections;
/*footer */
/* Get the first footer of the first section */
objFirstSec = objSecs.Item(1);
objFirstSecFooters = objFirstSec.Footers;
objFirstSecFirstFooter = objFirstSecFooters.Item(1);
sFooterRange = objFirstSecFirstFooter.Range;
/* Get the original footer text */
sOrigFooterText = sFooterRange.Text;
/* Set the new footer text */
sFooterRange.Text = "Nr #auftrag#";
/* Get the new footer text */
sNewFooterText = sFooterRange.Text;
/* set printer */
newApp = objDoc.Application;
newApp.ActivePrinter = "HP LaserJet 4000 Series PCL";
ActivePrinter = "HP LaserJet 4000 Series PCL";
</cfscript>
<!--- Vorbereiten drucken PRN-File --->
<!--- Create variables for true and false values --->
<cfset comtrue = isbinary(0)>
<cfset comfalse = isbinary('a')>
<!--- zuerst komplette Datei als DOC drucken --->
<cfset ret = objDoc.SaveAs("c:\#namedoc#.doc"

>
<cfscript>
// WORD file path
WORDFilePath = "c:\inetpub\
// Destination path for printed output
PrintFile = "c:\#namedoc#.prn";
// Disable alerts such as: 'Save this document?'
objWord.DisplayAlerts = false;
// Get the 'Documents' collection
objDoc = objWord.Documents;
// Open the WORD document
/* ist bereits geöffnet */
/* newDoc = objDoc.open(WORDFilePath); */
// Print the word document to a file
newDoc.PrintOut(comFalse, comTrue,0,PrintFile);
// Close the document
newDoc.Close();
// Quit Word
objWord.Quit();
</cfscript>
<!--- testen PRN-File in DOS: --->
<!--- copy /B b1.prn LPT1: --->
Best regards from
Toon