Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word mailmerge with excel error
Message
From
10/07/2007 07:43:48
 
 
To
10/07/2007 07:01:13
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01238712
Message ID:
01238822
Views:
16
Here are the problems.
1) I use office 2007

2) This line
.OpenDataSource(m.lcSourceDoc) && Set file as data source for mailmerge
hangs VFP with the infamous Switch to/ Retry error message.
Once I release VFP9.sp2 I get to a word dialog which was NOT visible before
asking what the field delimiter is. Can that be suppressed? mabe one of those many other parameters of OpenDataSource could eliminate the invisible prompt.
(BTW) the same happens when I use a CSV file type

Thanks
Peter





>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
Peter Cortiel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform