Board index » delphi » : Mail Merge Word97 V.S. Word2000, MailMergeOpenDataSource

: Mail Merge Word97 V.S. Word2000, MailMergeOpenDataSource

I am having trouble where I have a number of *.doc files which are mail
merge documents. The datasource was always in 'C:\temp\mailmerge.asc'
(text file with tab and enter delimiters) during design of the doc
files. Works fine as long as all of our customers have a C drive.
However some don't. With Word2000, the call to
varWord.MailMergeOpenDataSource( 'F:\temp\mailmerge.asc', 0, False,
True, False ) works great. Word2000 finds the datasource even though it
isn't in the same spot as when the doc file was created. However with
Word97, it seems to ignore this command and brings up a prompt asking
for the datasource file if it can't find the datasource file that was in
existence when the doc was created.. Is there any way to tell Word97
where the datasource is without user intervention?

procedure TForm1.btnOLEWordBasicClick(Sender: TObject);
var
  VWord: Variant;
begin
  VWord := CreateOLEObject( 'Word.Basic' );
  VWord.AppShow;
  VWord.FileOpen( 'c:\temp\FormLetter.doc' );
  VWord.AddAddIn( 'c:\temp\MyDot.dot, 1 );
  VWord.MailMergeOpenDataSource( 'f:\temp\mailmerge.asc', 0 );
  VWord.MailMergeToDoc;
end;

Daniel Raith
srdan...@hotmail.com

 

Re:: Mail Merge Word97 V.S. Word2000, MailMergeOpenDataSource


I got it to work with Word 97 and word 2000 using the following code. In
case anyone is interested.

procedure TForm1.btnOLEWordBasicClick(Sender: TObject);
var
  VWord: Variant;
  SaveDocumentType: Variant;
begin
  VWord := GetOrCreateObject( 'Word.Basic' );
  VWord.AppShow;
  VWord.FileOpen( edtDOC.Text );

  SaveDocumentType := VWord.MailMergeMainDocumentType;
  // Set the document type to what it was, this removes the datasource
stored in the active document!
  VWord.MailMergeMainDocumentType( SaveDocumentType );

  VWord.AddAddIn( edtDOT.Text, 1 );
  VWord.MailMergeOpenDataSource( edtTXT.Text, 0 );
  VWord.MailMergeToDoc;
end;

Daniel Raith
srdan...@hotmail.com

Quote
Daniel Raith wrote:
> I am having trouble where I have a number of *.doc files which are mail
> merge documents. The datasource was always in 'C:\temp\mailmerge.asc'
> (text file with tab and enter delimiters) during design of the doc
> files. Works fine as long as all of our customers have a C drive.
> However some don't. With Word2000, the call to
> varWord.MailMergeOpenDataSource( 'F:\temp\mailmerge.asc', 0, False,
> True, False ) works great. Word2000 finds the datasource even though it
> isn't in the same spot as when the doc file was created. However with
> Word97, it seems to ignore this command and brings up a prompt asking
> for the datasource file if it can't find the datasource file that was in
> existence when the doc was created.. Is there any way to tell Word97
> where the datasource is without user intervention?

> procedure TForm1.btnOLEWordBasicClick(Sender: TObject);
> var
>   VWord: Variant;
> begin
>   VWord := CreateOLEObject( 'Word.Basic' );
>   VWord.AppShow;
>   VWord.FileOpen( 'c:\temp\FormLetter.doc' );
>   VWord.AddAddIn( 'c:\temp\MyDot.dot, 1 );
>   VWord.MailMergeOpenDataSource( 'f:\temp\mailmerge.asc', 0 );
>   VWord.MailMergeToDoc;
> end;

> Daniel Raith
> srdan...@hotmail.com

Re:: Mail Merge Word97 V.S. Word2000, MailMergeOpenDataSource


I have had this problem, and got around it with Word97 by keeping another
document in another directory which you could guarantee to be the there,
like the Executuable directory and then changing to the one you need at
runtime.
FWIW
I have found HTML tables a more reliable way of importing data into a word
mail merge.
Regards Jonathan
Quote
"Daniel Raith" <srdan...@hotmail.com> wrote in message

news:3856E740.7B3BA999@hotmail.com...
Quote
> I am having trouble where I have a number of *.doc files which are mail
> merge documents. The datasource was always in 'C:\temp\mailmerge.asc'
> (text file with tab and enter delimiters) during design of the doc
> files. Works fine as long as all of our customers have a C drive.
> However some don't. With Word2000, the call to
> varWord.MailMergeOpenDataSource( 'F:\temp\mailmerge.asc', 0, False,
> True, False ) works great. Word2000 finds the datasource even though it
> isn't in the same spot as when the doc file was created. However with
> Word97, it seems to ignore this command and brings up a prompt asking
> for the datasource file if it can't find the datasource file that was in
> existence when the doc was created.. Is there any way to tell Word97
> where the datasource is without user intervention?

> procedure TForm1.btnOLEWordBasicClick(Sender: TObject);
> var
>   VWord: Variant;
> begin
>   VWord := CreateOLEObject( 'Word.Basic' );
>   VWord.AppShow;
>   VWord.FileOpen( 'c:\temp\FormLetter.doc' );
>   VWord.AddAddIn( 'c:\temp\MyDot.dot, 1 );
>   VWord.MailMergeOpenDataSource( 'f:\temp\mailmerge.asc', 0 );
>   VWord.MailMergeToDoc;
> end;

> Daniel Raith
> srdan...@hotmail.com

Other Threads