Board index » delphi » CL - Word97 - mailmerge

CL - Word97 - mailmerge

I have succeeded in automating a mailmerge
from within D3 (using word_tlb.pas).
However, I would like to close the main document
after merging the data.
Does anyone know what I am talking about ?

--
Kees Lagendijk
--------------

visit http://www.casema.net/~kens/
for free components

"Messing things up is easy
   but to really create chaos
   you need a computer..."

 

Re:CL - Word97 - mailmerge


Quote
"Kees Lagendijk" <k...@REMOVETHIScasema.net> wrote:
>I have succeeded in automating a mailmerge from within D3 (using word_tlb.pas).
>However, I would like to close the main document after merging the data.
>Does anyone know what I am talking about?

Do you want to save the main document with or without changes?

--
Regards,
Chris Roberts

Re:CL - Word97 - mailmerge


Quote
>>I have succeeded in automating a mailmerge from within D3 (using
word_tlb.pas).
>>However, I would like to close the main document after merging the data.
>>Does anyone know what I am talking about?

>Do you want to save the main document with or without changes?

>--
>Regards,
>Chris Roberts

without the changes !

Kees

Re:CL - Word97 - mailmerge


Quote
"Kees Lagendijk" <k...@REMOVETHIScasema.net> wrote:
>>>I have succeeded in automating a mailmerge from within D3 (using
>>>word_tlb.pas).
>>>However, I would like to close the main document after merging the data.
>>>Does anyone know what I am talking about?

>>Do you want to save the main document with or without changes?
>without the changes !

The following closes Word without saving changes.
========
// global variables
var
  WordApp: _Application;
{$IFDEF VER100}
  EmptyParam: OleVariant;
{$ENDIF}

// quit Word without saving changes
procedure TForm1.FormDestroy(Sender: TObject);
var
  SaveChanges: OleVariant;
begin
  try
    if Assigned(WordApp) then
    begin
      SaveChanges := wdDoNotSaveChanges;
      WordApp.Quit(SaveChanges, EmptyParam, EmptyParam);
    end;
  except
    // just get out of here - too late to do anything else.
  end;
end;

initialization
{$IFDEF VER100}
  TVarData(EmptyParam).VType := varError;
  TVarData(EmptyParam).VError := DISP_E_PARAMNOTFOUND;
{$ENDIF}
end.
========

// close a document without saving changes

var
  SaveChanges: OleVariant;
  aDoc: _Document;

  SaveChanges := wdDoNotSaveChanges;
  aDoc.Close(SaveChanges, EmptyParam, EmptyParam);
========

--
Regards,
Chris Roberts

Re:CL - Word97 - mailmerge


Quote
>// close a document without saving changes

>var
>  SaveChanges: OleVariant;
>  aDoc: _Document;

>  SaveChanges := wdDoNotSaveChanges;
>  aDoc.Close(SaveChanges, EmptyParam, EmptyParam);
>========

>--
>Regards,
>Chris Roberts

So far, so good !
But when I am done with the mailmerge there are two documents
open: the maindoc and the doc in which the merged data is
placed. I do not want the user to be able to alter the maindoc,
so I want to close it before it all become visible...

?

Kees

Re:CL - Word97 - mailmerge


Quote
"Kees Lagendijk" <k...@REMOVETHIScasema.net> wrote:
>But when I am done with the mailmerge there are two documents
>open: the maindoc and the doc in which the merged data is
>placed. I do not want the user to be able to alter the maindoc,
>so I want to close it before it all become visible...

The easiest method is to use your own instance of Word with Visible :=
false;  They can't change what they can't see.

--
Regards,
Chris Roberts

Other Threads