Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word - Bookmark 1

Status
Not open for further replies.

pgaec

Programmer
Aug 4, 2003
161
AU
Hi all,

I have a word document with some bookmarks.
I want my PB app to open the word document and fill in values [retrieved from database] at the bookmarks

Can anyone send me some sample code related to this

cheers
MM
 
I would look into using OLE for this process are we talking bookmarks or mail merge fields?
 
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 = ''

iole_word.activedocument.bookmarks.item('buyer').range.text = ls_name
iole_word.activedocument.bookmarks.item('buyerfax').range.text = ls_fax
iole_word.activedocument.bookmarks.item('buyeremail').range.text = 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...
 
thanks for that mbalent.
much appreciated..i will give it a try and will get back to ya...


cheers
MM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top