Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Mail Merge in Office 2003
Message
De
28/09/2004 02:29:56
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/09/2004 17:10:40
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00946435
Message ID:
00946551
Vues:
18
Jim,
I think this is book specific question and should keep my hands off.
Just to add .02 cents I don't see a need to create header source first (didn't understand comment about SIM).
FWIW just keep away from ODBC and have a tab delimited txt file as data source (add headers as first line). Word knows how to open it. IOW what I mean why just supply a header when you can both supply header and data at one shot.
Cetin

>I read the other threads and they don't quite fit. We use the Hentzenwerke book on Office automation to do mail merges through word. But we use a header and a Word table as the data set - filling it from within our program. Works fine in OFFICE 2000 and earlier and this also works to do a mail merge on an existing document in OFFICE 2003 but we cannot get it to see that this is a WORD document so we cannot create new letters or update the mail merge fields showing up on existing ones. I couldn't see any clear documentation on how WORD handles tables in 2003 like this.
>
>We did this to avoid problems with ODBC as others have encountered and also exporting to Excel with large text fields like memo fields that would get cut off.
>
>Jim
>
>Below is the overall code to add a new letter:
>
> *Update the data list header (create it if it doesn't exist). Do this first
> *so user not confused by WORD opening up and having to backtrack to SIM to
> *make changes.
> LOCAL lcfield, llchange
> lcfield = ''
> llchange= .f.
> DO updhdr WITH filenam, lcfield, llchange
>
> RELEASE ALL LIKE o_word*
> RELEASE ALL LIKE o_doc*
> o_word = createobject("Word.Application")
> o_doc = o_word.documents.add()
> *1/16/02 JAS Added '"' around path
> o_word.activedocument.saveas('"'+gc_letpath+RTRIM(filenam)+'.DOC'+'"')
> o_doc.application.visible = .T. &&makes that application come up
>
> *Now create a header source - this is a DOC file that just contains
> *the field information for the WORD document we are doing a merge for.
> *This turns the document into a merge document as well.
> IF llchange
> DO attachdr WITH filenam, lcfield
> ENDIF
>
>Here is our Edit section:
>
> *Update the data list header (create it if it doesn't exist). Do this first
> *so user not confused by WORD opening up and having to backtrack to SIM to
> *make changes.
> LOCAL lcfield, llchange
> lcfield = ''
> llchange= .f.
> DO updhdr WITH txt_file, lcfield, llchange
>
> PRIVATE o_doc
> RELEASE ALL LIKE o_doc*
> *1/16/02 JAS Added '"' around path
> *o_doc = getobject('"'+ALLTRIM(txt_file)+'"') &&opens up the document in appropriate MSOFFICE tool
> *Redid so document open in WORD in OFFICE 97 - 1/16/02 JAs
> o_word = createobject("Word.Application")
> o_doc = o_word.documents.open('"'+ALLTRIM(txt_file)+'"')
> o_doc.application.visible = .T. &&makes that application come up
>
> *Attach the data list header.
> IF llchange
> DO attachdr WITH txt_file, lcfield
> ENDIF
>
>Attachdr is below:
>
>*********************************************************************
>PROC attachdr
>*********************************************************************
>*Attaches header to open WORD document & checks if LETT_LST has info
>*properly stored.
>*10/21/01 JAS Initial version
>
>PARAMETER cfilenam, cfieldlist &&name of the document.
>
>local laheader, lcfilenam
>
>*Remove any path stuff - just want the name w/o extension or path.
>lcfilenam = cfilenam
>lcfilenam = FILEPAR2(lcfilenam) &&1/20/02 JAS
>
>*IF AT('.',lcfilenam) > 0
>* lcfilenam = SUBSTR(lcfilenam,1,AT('.',lcfilenam)-1)
>*ENDIF
>*DO WHILE AT('\',lcfilenam) > 0 &&strip leading dashes
>* lcfilenam = RIGHT(lcfilenam,LEN(lcfilenam)-AT('\',lcfilenam))
>*ENDDO
>
>lcfilenam = UPPER(ALLTRIM(lcfilenam))
>
>*Attach the header to the new document or update it for an existing one.
>*Need to use unique name since no simple way of removing header from an
>*existing merge document.
>WAIT WINDOW 'Creating New Merge Document Header' TIMEOUT .5
>DIME laheader[1,6] &&since local must initialize
>STORE '' TO laheader
>*1/16/02 JAS rename the header to .HDR extension so not confused with the documents
>*=ADIR(laheader, gc_letpath+lcfilenam+'_HEADER*.DOC')
>=ADIR(laheader, gc_letpath+lcfilenam+'_HEADER*.*')
>*1/16/02 JAS Added '"' around path
>*o_doc.mailmerge.createheadersource(gc_letpath+lcfilenam+'_HEADER'+ALLTRIM(SUBSTR(SYS(2015),3,8))+'.DOC', , , cfieldlist)
>o_doc.mailmerge.createheadersource('"'+gc_letpath+lcfilenam+'_HEADER'+ALLTRIM(SUBSTR(SYS(2015),3,8))+'.HDR'+'"' , , , cfieldlist)
>*Save new header
>o_doc.save()
>
>*Remove all of the old headers
>IF TYPE('laheader') = 'C'
> FOR lnheader = 1 TO ALEN(laheader,1)
> WAIT WINDOW 'Removing old header '+laheader[lnheader,1] TIMEOUT .5
> ERASE gc_letpath+laheader[lnheader,1]
> ENDFOR
>ENDIF
>
>RETURN
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform