Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word mailmerge with excel error
Message
De
10/07/2007 07:01:13
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
09/07/2007 19:31:46
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Divers
Thread ID:
01238712
Message ID:
01238813
Vues:
23
This message has been marked as the solution to the initial question of the thread.
BTW I found the original code:
Select * From customer Where country='USA' Into Cursor mergethese
MergeIt('mergethese')

Function MergeIt
Lparameters  tcAlias, tcTemplateDoc
Local nLocaleID,lcTemp,lcHeader
Local loWord,llToPrinter,lcSourceDoc

*** set the LOCALEID to English
nlLocaleId=Sys(3004)  && Save local id
=Sys(3006,1033)       && We will be sending instructions in English
*** set the LOCALEID to English

* Prepare source
Select (m.tcAlias)
lcTemp = Sys(2015)+'.tmp'
Copy To (lcTemp) Type Delimited With "" With Tab
AFIELDS(laFields)
lcHeader = ''
For ix = 1 To Fcount()
    lcHeader = lcHeader + ;
        Iif(Empty(m.lcHeader),'',Chr(9)) + ;
        Field(m.ix)
Endfor
lcSourceDoc = Sys(5)+Curdir()+'MergeSource.txt'
Strtofile(m.lcHeader+Chr(13)+Chr(10)+Filetostr(m.lcTemp),m.lcSourceDoc)
Erase (m.lcTemp)

loWord=Createobject("word.application")	&& Create word object
With loWord
    If Empty(m.tcTemplateDoc) && No template
        .documents.Add()  && New file
    Else
        .documents.Add(m.lcTemplateDoc)  && Open a template
    Endif
    With .Activedocument.Mailmerge
        .OpenDataSource(m.lcSourceDoc) && Set file as data source for mailmerge
        .EditMainDocument	&& Activate the main document

* Just to sample programmatic writing
        .Application.Selection.TypeText("Company : ")
        .Fields.Add(.Application.Selection.Range,'company')
        .Application.Selection.TypeText(Chr(13)+"Dear contact : ")
        .Fields.Add(.Application.Selection.Range,'contact')
        .Application.Selection.TypeText(Chr(13)+"Blah blah ...."+Chr(13))
* Just to sample programmatic writing
*!*	FOR EACH oFld IN .Fields
*!*	? GETWORDNUM(oFld.Code.Text,2)
*!*	endfor
    Endwith
    .Visible = .T.  && Show word app
    .Activate  && Make it the active foreground app
Endwith

**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
Adding header line separately because having a tab delimited text is better and you can control field names to be different than in source.
Cetin
Ç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