Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word 2003 automation Problem
Message
De
12/08/2004 12:54:56
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00902166
Message ID:
00932812
Vues:
15
I never encountered that error. I don't have word2003 to check if it's specific to that.
Cetin

>Hi Cetin... Just getting back to this now.
>
>I used a modified version of your code to create a Tab delimited .txt
> file and tried to use it in Mailmerge, directly from within Word initially
> just to play around with it. (Not going near VFP)
>
>It reads in the data ok, but it gives an error on every record as folows:
> Record x contains too few detail fields (x = record number)
>Within Word it seems to recongnise the Tab delimiter ok, and displays
> the records correctly in the Word grid.
>
>Do you know what causes this message
>(I am a bit reluctant to try the VFP automation if it gives these messages
> directly in Word)
>
>Regards,
>
>Gerard
>
>
>
>
>
>
>>Hi Gerard,
>>Sorry I've been quite busy nowadays, finally project got out of door.
>>Here is a sample doing it creating and using a doc as the source :
>>
>>
>>#include "wdconst.h"
>>Select * ;
>>	from (_samples+'data\customer') ;
>>	where country = 'USA' ;
>>	into Cursor Tempreport
>>
>>lcTemp = Sys(2015)+'.tmp'
>>lnFields = Fcount()
>>Copy To (lcTemp) Type Delimited With "" With Tab
>>lcHeader = ''
>>For ix = 1 To Fcount()
>>	lcHeader = lcHeader + Iif(Empty(m.lcHeader),'',Chr(9)) + ;
>>		'A_long_header_for_field_'+Field(m.ix)+'_here'
>>Endfor
>>
>>lcSourceDoc = 'c:\temp\Source.txt'
>>Strtofile(m.lcHeader+Chr(13)+Chr(10)+;
>>	Filetostr(m.lcTemp),m.lcSourceDoc)
>>Erase (m.lcTemp)
>>
>>*** 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
>>
>>Local oWordDocument, llToPrinter, lcTempDataDoc
>>oWord=Createobject("word.application")	&& Create word object
>>With oWord
>>	.documents.Add  && New file or open a template
>>	With .Activedocument.Mailmerge
>>          *
>>          * Set file as data source for mailmerge
>>          * File is a tab delimited text file with header line
>>          * Since word's default settings perfectly fit
>>          * opening a tab delimited file as if it were a table
>>          * this is just we want - no need for a conversion
>>          *
>>          * Or thinking any Word owner should also have Excel
>>          * (not true always) you might open the text file with
>>          * Excel and set that as a datasource
>>          *
>>          .OpenDataSource(m.lcSourceDoc)
>>	  .EditMainDocument	&& Activate the main document
>>	Endwith
>>	.Application.Selection.TypeText("Dear,"+Chr(13))
>>	With .Application.Selection.Font
>>		.Name = 'Times New Roman'
>>		.Italic = .T.
>>		.Size = 14
>>	Endwith
>>	.Activedocument.Mailmerge.Fields.Add(.Application.Selection.Range, ;
>>   'A_long_header_for_field_Contact_here')
>>	.Application.Selection.TypeText(Chr(13))
>>	.Activedocument.Mailmerge.Fields.Add(.Application.Selection.Range, ;
>>   'A_long_header_for_field_Company_here')
>>	With .Application.Selection.Font
>>		.Italic = .F.
>>		.Name = 'Arial'
>>		.Size = 10
>>	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))
>>
>>As you see this is a sample to OpenDataSource BUT using an office friendly source which is simply another word doc (and word already knows how to open a txt file, simple and fast).
>>PS:
>>With oWord
>>	.documents.Add  && New file or open a template
>>
>>If you instead write :
>>
>>With oWord
>>	.documents.Add("c:\myPath\MyTemplate.doc")
>>
You'd be using a presaved template.
>>
>>Cetin
>>
>>>Hi Cetin.
>>>
>>>I sort of thought your 'Set Flamesuit' was a joke....but you never know !!!
>>>
>>>I dont have any love for OpenDatSource,but is there another way of driving Word Mailmerge 2003 from VFP without it.
>>>
>>>Regards,
>>>
>>>Gerard
Ç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
Répondre
Fil
Voir

Click here to load this message in the networking platform