>LPARAMETERS oMemoDoc,sHeader,sData,cGrpId >ASSERT VARTYPE(oMemoDoc)#'O' MESSAGE "Developer stop at MemoDoc for testing" > >LOCAL oMergedDocument >* word app reference for mailmerge >oWordApp = oMemoDoc.application >APPLICATION.OLERequestPendingTimeout = 0 && 0 means no busy error message >* make sure the merged document is selected >oMemoDoc.select() >*WAIT WINDOW "Before open header, data source" >* attach header & data source to document >oMemoDoc.MailMerge.OpenHeaderSource(sHeader) >>Next line is where I get "File in Use"
>oMemoDoc.MailMerge.OpenDataSource(sData) >*WAIT WINDOW "header and data source open"+sHeader+', '+sData >* Perform the mail merge >oMemoDoc.MailMerge.Execute() > >* reference the merged document prior to printing >oMergedDocument = oWordApp.ActiveDocument >*WAIT WINDOW "Active Doc printing"+(oApp.UserPath+cGrpId+".doc") > >* save merged result >IF LOWER(SUBSTR(oMemoDoc.name,RAT('_',oMemoDoc.name)+1,2)) = "pn" > oMergedDocument.SaveAs(oApp.UserPath+cGrpId+"Lst.doc") >* WAIT WINDOW "Doc saved"+(oApp.UserPath+cGrpId+"Lst.doc") >ENDIF > >* print merged result >oMergedDocument.PrintOut(.T.) >wait "" timeout 5 >>