>Hello.
>
>I am looking for a way to open a word document or .dot (bassically to execute a word macro) file from a Visual Foxpro (6.0) application. I've tried the RUN command as well as others, but nothing has worked so far.
>
>Any help would be appreciated.
>
>Thank you.
>
>Yan Vaillancourt
You have to use OLE automation with MS Word.
Similar to this:
PUBLIC oWordObj
LOCAL lnCountMarks, lnForCount, lcMarkName && local variables to store some temporary names
* Word Constants
#DEFINE wdStory 6
#DEFINE wdExtend 1
#DEFINE wdDoNotSaveChanges 0
lcDocFile =gs_MailLoc+"DistConf.doc"
oWordObj=CREATEOBJECT("Word.Application") && Create object to Word Class
oWordObj.VISIBLE=.T. && MS Word instance invisible
oWordObj.Documents.OPEN(lcDocFile) && Open Template file
* Retrieve the number of bookmarks defined in the document
lnCountMarks=oWordObj.ActiveDocument.Bookmarks.COUNT
IF lnCountMarks<>0 && at least 1 bookmark in the document
* Store bookmarks in array - prepare to process
DIMENSION laMark[lnCountMarks]
* Fill the array with bookmarks names
FOR lnForCount=1 TO lnCountMarks
laMark[lnForCount]=oWordObj.ActiveDocument.Bookmarks(lnForCount).NAME
ENDFOR
ELSE
RETURN
ENDIF
SCAN
oWordObj.Documents.OPEN(lcDocFile) && Open Template file
* Run throw the document and insert fields instead of bookmarks
FOR lnForCount=1 TO lnCountMarks
lcMarkName=UPPER(laMark[lnForCount])
oWordObj.ActiveDocument.Bookmarks(lcMarkName).SELECT
DO CASE
CASE UPPER(lcMarkName)="EENO"
oWordObj.SELECTION.TypeText(eeno)
CASE UPPER(lcMarkName)="GRNO"
oWordObj.SELECTION.TypeText(grno)
CASE UPPER(lcMarkName)="FULLNAME"
oWordObj.SELECTION.TypeText(FULLNAME)
CASE UPPER(lcMarkName)="SALNAME"
oWordObj.SELECTION.TypeText(salname)
CASE UPPER(lcMarkName)="ADDR1"
oWordObj.SELECTION.TypeText(Addr1)
CASE UPPER(lcMarkName)="ADDR2"
oWordObj.SELECTION.TypeText(Addr2)
CASE UPPER(lcMarkName)="ADDR3"
oWordObj.SELECTION.TypeText(Addr3)
CASE UPPER(lcMarkName)="ST1NAME"
oWordObj.SELECTION.TypeText(st1name)
CASE UPPER(lcMarkName)="ST2NAME"
oWordObj.SELECTION.TypeText(st2name)
CASE UPPER(lcMarkName)="LC1NAME"
oWordObj.SELECTION.TypeText(lc1name)
CASE UPPER(lcMarkName)="LC2NAME"
oWordObj.SELECTION.TypeText(lc2name)
CASE UPPER(lcMarkName)="FEDTAX"
oWordObj.SELECTION.TypeText(fedtax)
CASE UPPER(lcMarkName)="FICATAX"
oWordObj.SELECTION.TypeText(ficatax)
CASE UPPER(lcMarkName)="STT1TAX"
oWordObj.SELECTION.TypeText(stt1tax)
CASE UPPER(lcMarkName)="STT2TAX"
oWordObj.SELECTION.TypeText(stt2tax)
CASE UPPER(lcMarkName)="LCL1TAX"
oWordObj.SELECTION.TypeText(lcl1tax)
CASE UPPER(lcMarkName)="LCL2TAX"
oWordObj.SELECTION.TypeText(lcl2tax)
CASE UPPER(lcMarkName)="ACT_DATE"
oWordObj.SELECTION.TypeText(ALLTRIM(act_date))
CASE UPPER(lcMarkName)="VST_SHRS"
oWordObj.SELECTION.TypeText(ALLTRIM(vst_shrs))
CASE UPPER(lcMarkName)="DIST_SHRS"
oWordObj.SELECTION.TypeText(ALLTRIM(dist_shrs))
CASE UPPER(lcMarkName)="DEFSHRS"
oWordObj.SELECTION.TypeText(ALLTRIM(defshrs))
CASE UPPER(lcMarkName)="NETSHRS"
oWordObj.SELECTION.TypeText(ALLTRIM(netshrs))
CASE UPPER(lcMarkName)="GNT_DATE"
oWordObj.SELECTION.TypeText(ALLTRIM(gnt_date))
CASE UPPER(lcMarkName)="DIST_SHRS2"
oWordObj.SELECTION.TypeText(ALLTRIM(dist_shrs2))
CASE UPPER(lcMarkName)="VST_SHRS2"
oWordObj.SELECTION.TypeText(ALLTRIM(vst_shrs2))
CASE UPPER(lcMarkName)="ST_FMV"
oWordObj.SELECTION.TypeText(ALLTRIM(st_fmv))
CASE UPPER(lcMarkName)="ST_FMV2"
oWordObj.SELECTION.TypeText(ALLTRIM(st_fmv2))
CASE UPPER(lcMarkName)="TAXYEAR"
oWordObj.SELECTION.TypeText(taxyear)
CASE UPPER(lcMarkName)="TAXYEAR2"
oWordObj.SELECTION.TypeText(taxyear2)
CASE UPPER(lcMarkName)="FMVDATE"
oWordObj.SELECTION.TypeText(ALLTRIM(fmvdate))
CASE UPPER(lcMarkName)="FEDTXINC"
oWordObj.SELECTION.TypeText(ALLTRIM(fedtxinc))
CASE UPPER(lcMarkName)="FICATXINC"
oWordObj.SELECTION.TypeText(ALLTRIM(ficatxinc))
CASE UPPER(lcMarkName)="TOTTAX"
oWordObj.SELECTION.TypeText(ALLTRIM(tottax))
CASE UPPER(lcMarkName)="SHRTAX"
oWordObj.SELECTION.TypeText(ALLTRIM(shrtax))
CASE UPPER(lcMarkName)="SHRTAX2"
oWordObj.SELECTION.TypeText(ALLTRIM(shrtax2))
ENDCASE
ENDFOR
oWordObj.ActiveDocument.Content.SELECT && Select all document
* oWordObj.SELECTION.Homekey(wdStory)
* oWordObj.SELECTION.Endkey(wdStory,wdExtend)
oWordObj.SELECTION.RANGE.COPY && Copy all document to the ClipBoard
oWordObj.Documents.ADD && Open Temporary New file
oWordObj.SELECTION.RANGE.Paste && Restore document from ClipBoard
oWordObj.ActiveDocument.PrintOut && Print/Preview Document from temporary file
oWordObj.ActiveDocument.CLOSE(0) && Close temporary file after printing
oWordObj.ActiveDocument.CLOSE(0) && Close template
ENDSCAN
RELEASE lnCountMarks, lnForCount, lcMarkName, oWordObj
RETURN
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement