Board index » delphi » How to use Merge method from Word_TLB

How to use Merge method from Word_TLB

Hello,

Does anybody have a working example using Merge method from
Word_TLB? I can not get it working..

Thank you in advance.

Regards,
Eugene.

 

Re:How to use Merge method from Word_TLB


Here is some code from one of my components. I stripped out non-relevant
code.

HTH
-Sen

var
  WordApp,
  MainDoc,
  MergedDoc : Variant;
.......
begin
  Screen.Cursor := crHourGlass;
  try
    if UseExisting then
      try
        WordApp := GetActiveOleObject('Word.Application');
      except
        WordApp := CreateOleObject('Word.Application');
      end
    else
        WordApp := CreateOleObject('Word.Application');

    try
      WordApp.Visible := (FDestination = rdSendToNewDocument);

.........
        MainDoc.MailMerge.OpenDataSource(wsTempFileName/*String Variable*/,
wdOpenFormatText, False, True, True, False,
          EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);

        MainDoc.MailMerge.Execute;

        MergedDoc := WordApp.ActiveDocument;
        if FDestination = rdSendToPrinter then
        begin
          MergedDoc.PrintOut(BackGround:=False, Copies := FCopies,
Collate:=FCollate);
          MergedDoc.Close(False, EmptyParam, False);
        end;

        MainDoc.Close(False, EmptyParam, False);
..........
    except on E : Exception do
      MessageDlg('Error creating mail merge.' + #13 + E.Message , mtError,
[], 0);
    end;

    while WordApp.BackgroundPrintingStatus > 0 do//wait for printing to
finish

  finally
    if (FDestination = rdSendToPrinter) and (not FUseExisting) then
      WordApp.Quit;
    DeleteFile(TempFileName);
    WordApp := Null;
    MainDoc := Null;
    MergedDoc := Null;

    Screen.Cursor := crDefault;
  end;
end;

Quote
> Does anybody have a working example using Merge method from
> Word_TLB? I can not get it working..

Re:How to use Merge method from Word_TLB


I was talking not about MailMerge..i need to merge two documents.
DocA = DocB + DocC

Re:How to use Merge method from Word_TLB


Oops! I misunderstood.
This should get you started:

implementation
uses
  Word_TLB, ComObj;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp,
  DocA : Variant;

begin
  WordApp := CreateOleObject('Word.Application');
  try
    WordApp.Visible := True;
    DocA := WordApp.Documents.Add('normal.dot');
    DocA.Range(Start:=0, End:=0).InsertFile('c:\temp\DocC.Doc');(*Insert Doc
C at very top*)
    DocA.Range(Start:=0, End:=0).InsertFile('c:\temp\DocB.Doc');(*INsert Doc
B at very top, B is now before C*)
    DocA.SaveAs(FileName := 'DocA.Doc'); (*Save*)
  finally
    WordApp := Null;
    DocA := Null;
  end;
end;

-Sen

Eugene V. Goldberg <eg...@sandy.ru> wrote in message
news:7nq9p3$ao911@forums.borland.com...

Quote
> I was talking not about MailMerge..i need to merge two documents.
> DocA = DocB + DocC

Other Threads