Welkom op het forum van startpagina!

Dit forum staat op alleen-lezen. Je kan hier informatie zoeken en oude berichten terugvinden, maar geen nieuwe berichten plaatsen.

Naar overzicht van alle forums

Delphi Automation

  • MPEG

    Weet iemand hoe je met Delphi een WordMerge kan uitvoeren. Delphi levert nl. wel de server componenten maar de helpfile ontbreken helaas.

  • dunpat

    Ik neem aan, dat je een mailmerge bedoelt. Dit is vrij eenvoudig (Mits je het “truckje” kent):

    1. Je start words op en neemt een macro op

    2. Je doet de gewenste stappen. In jou geval de acties die je normaliter onderneemt om een mailmerge te doen

    3. Je stopt de macro en bewerkt hem. De code die je dan ziet kun je vrij direct overzetten in Delphi.

    Voor meer info, zie VBA helpfile welke bij words, excel ed. worden toegevoegd.

    Hier is het concrete voorbeeld:

    ——————————————-

    unit Unit1;

    interface

    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    OleServer, Word97, StdCtrls;

    type

    TForm1 = class(TForm)

    WordApplication: TWordApplication;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

    private

    procedure WordConnect;

    procedure WordDisconnect;

    procedure MailMerge;

    { Private declarations }

    public

    { Public declarations }

    end;

    var

    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.WordDisconnect;

    begin

    WordApplication.Disconnect;

    end;

    procedure TForm1.WordConnect;

    begin

    WordApplication := TWordApplication.Create(nil);

    WordApplication.Connect;

    end;

    procedure TForm1.Button1Click(Sender: TObject);

    begin

    WordConnect;

    try

    WordApplication.Documents.Add(EmptyParam,EmptyParam);

    WordApplication.Visible := true;

    MailMerge;

    finally

    WordDisconnect;

    end;

    end;

    { HIER DE INHOUD VAN DE MACRO, zoals ik deze kreeg na doorlopen van de 3 stappen:

    Sub MacroNaam()

    '

    ' MacroNaam Macro

    ' Macro opgenomen op 16-02-01 door dunpat

    '

    ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

    ActiveDocument.MailMerge.OpenDataSource Name:= “bestand.xls” _

    , ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _

    AddToRecentFiles:=False, PasswordDocument:=“”, PasswordTemplate:=“”, _

    WritePasswordDocument:=“”, WritePasswordTemplate:=“”, Revert:=False, _

    Format:=wdOpenFormatAuto, Connection:=“Heel werkblad”, SQLStatement:=“”, _

    SQLStatement1:=“”

    Application.MailingLabel.DefaultPrintBarCode = False

    Application.MailingLabel.CreateNewDocument Name:=“”, Address:=“”, AutoText _

    :=“ExtraEtikettenMaken1”

    With ActiveDocument.MailMerge

    .Destination = wdSendToNewDocument

    .MailAsAttachment = False

    .MailAddressFieldName = “”

    .MailSubject = “”

    .SuppressBlankLines = True

    With .DataSource

    .FirstRecord = wdDefaultFirstRecord

    .LastRecord = wdDefaultLastRecord

    End With

    .Execute Pause:=True

    End With

    End Sub

    }

    {HIER DE UITWERKING van deze stappen}

    procedure TForm1.MailMerge;

    var

    _False: OleVariant;

    _True: OleVariant;

    EmptyStr: OleVariant;

    FileName: WideString;

    WritePasswordTemplate: OleVariant;

    Connection: OleVariant;

    AutoText: OleVariant;

    begin

    _False := False;

    _True := True;

    EmptyStr := '';

    WordApplication.ActiveDocument.MailMerge.MainDocumentType := wdMailingLabels;

    FileName := ‘bestand.xls’;

    WritePasswordTemplate := wdOpenFormatAuto;

    Connection := ‘Heel werkblad’;

    WordApplication.ActiveDocument.MailMerge.OpenDataSource(FileName,

    WritePasswordTemplate, {LET OP FORMAT NAAR VOOR}_False, _False, _True,

    _False, EmptyStr, EmptyStr, _False, {LET OP REVERT NAAR VOOR}EmptyStr,

    EmptyStr, Connection, EmptyStr, EmptyStr);

    WordApplication.MailingLabel.DefaultPrintBarCode := False;

    AutoText := ‘ExtraEtikettenMaken1’;

    WordApplication.MailingLabel.CreateNewDocument(EmptyStr, EmptyStr, AutoText,

    EmptyParam, EmptyParam);

    with WordApplication.ActiveDocument.MailMerge do

    begin

    Destination := wdSendToNewDocument;

    MailAsAttachment := False;

    MailAddressFieldName := '';

    MailSubject := '';

    SuppressBlankLines := True;

    with DataSource do begin

    FirstRecord := wdDefaultFirstRecord;

    LastRecord := wdDefaultLastRecord;

    end;

    Execute(_True);

    end;

    end;

    end.

    ——————————————-

    l8r

    dunpat