Here is some code from a pb8 app I work on. It is PFC based
and the example uses some stuff from the string service
The only 'tricky' part I have had problems with is saving
the 'real' document (and not updating my template doc) and not leaving it locked. I do this by doing a Word saveas, first as the document I want to save and secondly as a dummy document to remove the lock from the first one.
Hope this helps.
iole_word = CREATE oleobject
TRY
iole_word.connecttonewobject('word.application')
CATCH (runtimeerror a)
Messagebox('Error','Error connecting with MS Word. Process terminating.')
RETURN -1
END TRY
iole_word.visible = FALSE
ls_file = w_cpr_frame.is_template_loc
TRY
iole_word.Documents.open(ls_file)
CATCH (runtimeerror b)
Messagebox('Error','Error opening ' + ls_file_name + ' with MS Word. Process terminating.')
RETURN -1
END TRY
iole_word.activedocument.bookmarks.item('vendor').range.text = ids_xdex.getitemstring(1,'vendordesc')
ls_name = dw_buyer.getitemstring(1,'name')
ls_fax = dw_buyer.getitemstring(1,'fax')
ls_email = dw_buyer.getitemstring(1,'email')
IF IsNull(ls_name) THEN ls_name = ''
IF IsNull(ls_fax) THEN ls_fax = ''
IF IsNull(ls_email) THEN ls_email = ''
// build name for new document
ll_docno = lnv_nextkey.of_getnextkey("Document"
ls_doc = ids_xdex.getitemstring(1,'c_vendorid') + string(ll_docno) + '.DOC'
ll_strpos = lnv_string.of_lastpos(ls_file,'\')
IF (ll_strpos > 0) THEN
ls_file = Left(ls_file,ll_strpos) // strip off template name from ls_file
END IF
is_doc = ls_file + ls_doc
// save document before processing further
TRY
iole_word.activedocument.saveas(is_doc)
CATCH (runtimeerror c)
Messagebox('Error','Error saving document ' + is_doc + '. Process terminating.')
RETURN -1
END TRY
TRY
iole_word.activedocument.saveas('P:\temp.doc') // save 'dummy' so 'real' document is not locked
CATCH (runtimeerror d)
Messagebox('Error','Error saving temp document. Process terminating.')
RETURN -1
END TRY
// word ole object destroyed elsewhere...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.