Article ID: 172847
Article Last Modified on 2/9/2006
Dear NAME,
CONTENT
Sincerely,
John Smith
Field name Type Size
-----------------------------
Content General 4
Name Character 10
LOCAL oWordObj
* Open table
IF !USED("mydoc")
USE mydoc
ELSE
SELECT mydoc
ENDIF
* Open a Word Object
oWordObj = CREATEOBJECT("Word.Application")
* Next open the original document in a second window
oWordObj.Documents.Open("C:\VFP50\mytest.doc")
* Retrieve the number of bookmarks defined in DOC
pnCountMarks = oWordObj.ActiveDocument.Bookmarks.Count
* Store bookmarks in an array
DIMENSION aMark[pnCountMarks]
FOR pnCount = 1 TO pnCountMarks
aMark[pnCount] = oWordObj.ActiveDocument.Bookmarks(pnCount).Name
ENDFOR
* Loop through all the bookmarks in the document
FOR pnCount = 1 TO pnCountMarks
pcMarkName = UPPER(aMark[pnCount])
* Move to the next bookmark
WITH oWordObj.ActiveDocument.Bookmarks(pcMarkName).Range
DO CASE
CASE pcMarkName = "ANAME"
.text = ALLTRIM(Name)
CASE pcMarkName = "CONTENT" && goes to bookmark
oWordObj.WordBasic.ww7_editgoto("CONTENT")
* Starts Word
oWord=GETOBJECT(,"WORD.basic")
* Creates Form in VFP
frmWord=CREATEOBJECT("FORM")
* Adds OLE object to form
frmWord.ADDOBJECT("OBJWORDDOC","OLEBOUNDCONTROL")
* Sets the control source
frmWord.OBJWORDDOC.CONTROLSOURCE="mydoc.content"
* frmWord.show
frmWord.OBJWORDDOC.DoVerb(0) && Default Word doc is 'Edit'
oWord.EditSelectAll
oWord.EditCopy
oWordObj.WordBasic.editpaste
ENDCASE
ENDWITH
ENDFOR
* Release the Word.Basic object that edits the General field
* contents, and close the Form that was opened to access the VFP
* table with that General field.
Release oWord
Release frmWord
* Save and Print the document
oWordObj.WordBasic.FilePrint(0) && Turn background printing off
WAIT WINDOW "Printing in Progress" TIMEOUT 3
oWordObj.WordBasic.FileSaveAs("c:\VFP50\DEMO1.DOC")
* Close Word
oWordObj.WordBasic.DocClose
* Quit Word, release the object and clear the desktop
oWOrdObj.Quit
Release oWordObj
Thisform.release
WITH oWordObj.ActiveDocument.Bookmarks(pcMarkName).Range
The error message follows:
Keywords: kbhowto kbinterop kbautomation KB172847