The following code sends a letter to MSword and works ok, but the documents are still openned somewhere even after the user has closed them. The OS re-opens them after a reboot and load of MWword:(
What is wrong with this code?
Also, what is the syntax to send a print the document form VFP with oword.visible= .f.
* Letters.prg
#Define cr chr(13)
#Define true .t.
#Define false .f.
oword=create('word.application')
oword.documents.add()
Select Letters
Browse FIELDS Name, Description, Letter
mCaption = TRIM(Letters.Name)
Select Master
Browse FIELDS name, buyer, City
mAcct = Acct
mName = Name
mAddr1 = Address
mCity = TRIM(City)+", "+State+" "+Zip
mBuyer = buyer
mCaption = mCaption+"-"+TRIM(mAcct)
oword.caption=mCaption
For i = 1 to 2
oword.Selection.insertafter(cr)
Endfor
oword.selection.insertafter(mmCo+cr)
oword.selection.insertafter(mmAdd1+cr)
oword.selection.insertafter(mmCity+cr)
For i = 1 to 2
oword.Selection.insertafter(cr)
Endfor
oword.Selection.insertafter(cr)
oword.selection.insertafter(mName+cr)
oword.selection.insertafter(mAddr1+cr)
oword.selection.insertafter(mCity+cr)
oword.Selection.insertafter(cr)
oword.activedocument.Bookmarks.add("date")
For i = 1 to 3
oword.Selection.insertafter(cr)
Endfor
oword.selection.insertafter('Dear ')
oword.activedocument.Bookmarks.add("salutation")
oword.Selection.insertafter(cr)
oword.activedocument.Bookmarks.add("bodytext")
oword.selection.Bookmarks('date').select
oword.selection.insertafter(date())
oword.selection.Bookmarks('salutation').select
mName = TRIM(mBuyer)+":"
oword.selection.insertafter(mName+cr)
Sele Letters
lc_memo=ALLTRIM(Letter)
oword.Selection.insertafter(cr)
oword.selection.insertafter(lc_memo+cr)
oword.selection.Bookmarks('bodytext').select
For i = 1 to 3
oword.Selection.insertafter(cr)
Endfor
SELE Userx
mSignature = PROPER(Userx.Name)
oword.selection.insertafter(repl('_',25))
oword.Selection.insertafter(cr)
oword.selection.insertafter(mSignature+cr)
Start=oword.selection.Bookmarks('date').select
End=oword.activedocument.Bookmarks("\ENDOFDOC").select
oword.visible= .t.
*end
One can acquire everything in solitude but character.
Stendhal (1783-1842)