Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Merge Doc in ColdFusion

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Has anyone sucessfully creaged a Merge document in Word via ColdFusion code?<br><br>Bruce
 
This code should do the job for you.

<!--- Try to connect to the Word application object --->
<CFTRY>
<!--- If it exists, connect to it --->
<CFOBJECT
ACTION=&quot;CONNECT&quot;
CLASS=&quot;Word.Application&quot;
NAME=&quot;objWord&quot;
TYPE=&quot;COM&quot;>
<CFCATCH>
<!--- The object doesn't exist, so create it --->
<CFOBJECT
ACTION=&quot;CREATE&quot;
CLASS=&quot;Word.Application&quot;
NAME=&quot;objWord&quot;
TYPE=&quot;COM&quot;>
</CFCATCH>
</CFTRY>

<CFSCRIPT>
/* This will open Word if running locally */
objWord.Visible = true;
/* This returns the 'Documents' collection of the Word object */
objDoc = objWord.Documents;
/* Specify a document to open */
newDoc = objDoc.open(&quot;C:\Netscape\Server4\docs\testing\New Folder\departmentletter.doc&quot;);
/* Use the merge template to create a new &quot;merged&quot; document */
objMerge = newDoc.MailMerge;
objMerge.Destination = 0;/* 0 = wdSendToNewDocument */
objMerge.Execute();
</cfscript>

<!--- Save the newly merged document as a new file --->
<cfloop collection=&quot;#objDoc#&quot; item=&quot;thisDoc&quot;>
<cfscript>
thisMM = thisDoc.MailMerge;
thisMMState = thisMM.state;
if (thisMMState eq 0) {
thisDoc.SaveAs(&quot;C:\Netscape\Server4\docs\testing\New Folder\departmentletter1.doc&quot;);
thisdoc.Close();
}
</cfscript>
</cfloop>

<CFLOOP COLLECTION=&quot;#OBJDOC#&quot; ITEM=&quot;thisDoc&quot;>
<CFSCRIPT>
thisDoc.Close();
</CFSCRIPT>
</CFLOOP>

<!--- Close Word on the server --->
<CFSCRIPT>
objWord.Quit();
</CFSCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top