LOCAL loo, cError, oDoc _VFP.autoyield = .F. loo = CREATEOBJECT( 'form' ) && This is a "dummy" form for holding the control loo.ADDOBJECT( 'oObject', 'oleWord' ) WITH loo.oObject.object.application oDoc = .documents.add( this.templates + 'APMM\' + oPage.oleBoundControl1.templatefilename ) cError = ON( 'ERROR' ) ON ERROR RETURN && MESSAGEBOX( 'Unable to initialize the document' ) EVAL( "this." + TRIM( STRTRAN( oPage.Caption, ' ', '_' ) ) + "( loo.oObject.object.application.wordBasic )" ) oDoc.activate() ON ERROR RETRY .wordbasic.filesaveas( TRIM( putfile( 'File Name', ; TRIM( oPage.caption ) + trim( baseproj.proj_no ) + '.doc', 'doc' ) ) ) ON ERROR &cError lNewDoc = .T. oPage.docfile.Value = oDoc.FullName oDoc.Close() ENDWITH loo.oObject.Object.Application.DisplayAlerts = 0 loo.oObject.object.application.quit()Then, I have methods for initializing the documents. The following is an example.
LPARAMETER o_Word o_Word.setformresult( "projectno", baseproj.proj_no ) o_Word.setformresult( "title", baseproj.projtitle ) o_Word.setformresult( "fy", baseproj.fy ) o_Word.setformresult( "remarks", baseproj.remarks ) RETURN .T.Right now this is all hardcoded, because just figuring out the automation took so much time. But, it would be straightforward to make it generic. The trick is what will the users name the merge fields? You either need a convention or you need to give them some kind of mapping utility.