Currently I use the following code which merges the document, saves a new merged document, and then closes the activedocument(s) and reload my saved merge document. The end result I want to achieve is to just have the merged document pulled up when the merge is complete. How can I close just the original document with the merge field codes. Closing the Activedocument works but since the new merged doc is the activedocument I have to close both and then reopen .
Below is my code....
** Merge
&&name of form document with merge fields
ofile="F:\FORMS\FORM1.DOC"
&&name of data source
odata="F:\DATA\DATA.DBF"
&&name of new file to be created
nfile="F:\DOCUMENT\FORM2.DOC"
&&opens form document
oDocument=oword.Documents.open(ofile)
&& Establishes merge document as formletter
oDocument.MailMerge.MainDocumentType= 0
&& Changes Data Source to odata
oDocument.MailMerge.OpenDataSource(odata)
&&Executes merge
oDocument.MailMerge.execute()
&&Saves merged document
oWord.ActiveDocument.SaveAs(nfile)
&&closes nfile
oword.ActiveDocument.close()
&&closes ofile
oword.ActiveDocument.close()
&&opens form document
oDocument=oword.Documents.open(nfile)
Andy
Below is my code....
** Merge
&&name of form document with merge fields
ofile="F:\FORMS\FORM1.DOC"
&&name of data source
odata="F:\DATA\DATA.DBF"
&&name of new file to be created
nfile="F:\DOCUMENT\FORM2.DOC"
&&opens form document
oDocument=oword.Documents.open(ofile)
&& Establishes merge document as formletter
oDocument.MailMerge.MainDocumentType= 0
&& Changes Data Source to odata
oDocument.MailMerge.OpenDataSource(odata)
&&Executes merge
oDocument.MailMerge.execute()
&&Saves merged document
oWord.ActiveDocument.SaveAs(nfile)
&&closes nfile
oword.ActiveDocument.close()
&&closes ofile
oword.ActiveDocument.close()
&&opens form document
oDocument=oword.Documents.open(nfile)
Andy