Registriert seit: 4. Mai 2003
Ort: Berlin
458 Beiträge
Delphi 7 Professional
|
Re: Serienbrief aus Textdatei
7. Jun 2005, 09:29
Hallo,
schau Dir mal die ekRtf Komponente an, die echt Klasse.
Wenn es die nicht sein soll, dann hilft dir der Code hier vielleicht weiter.
Code:
WordApplication1.Disconnect;
WordDocument1.Disconnect;
WordApplication1.Documents.OpenOld(WordDoc, emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam,
EmptyParam, emptyParam, emptyParam);
try
Data:= ExtractFilePath(Application.ExeName)+'\Temp\SerienTxt.txt';
WordApplication1.ActiveDocument.MailMerge.MainDocumentType:= wdFormLetters;
WordApplication1.ActiveDocument.MailMerge.OpenDataSource(Data, emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam);
WordDocument1.ConnectTo(WordApplication1.ActiveDocument);
Pause:= true;
Mail:= WordDocument1.MailMerge;
Mail.Destination:= wdSendToNewDocument;
Mail.Execute(Pause);
except
end;
WordDocument1.Close;
WordDocument1.Disconnect;
WordDocument1.ConnectTo(WordApplication1.ActiveDocument);
Bookmark:= 'Akz';
if WordApplication1.ActiveDocument.Bookmarks.Exists(Bookmark) then
begin
R:= WordApplication1.ActiveDocument.Bookmarks.Item(Bookmark).Range;
R.InsertAfter(Form1.QAkte.FieldByName('AAkz').AsString);
end;
Bookmark:= 'Datum';
if WordApplication1.ActiveDocument.Bookmarks.Exists(Bookmark) then
begin
R:= WordApplication1.ActiveDocument.Bookmarks.Item(Bookmark).Range;
R.InsertAfter(DateToStr(Now));
end;
Bookmark:= 'Rubrum';
if WordApplication1.ActiveDocument.Bookmarks.Exists(Bookmark) then
begin
R:= WordApplication1.ActiveDocument.Bookmarks.Item(Bookmark).Range;
R.InsertAfter(Form1.QAkte.FieldByName('ARubrum').AsString);
end;
Bookmark:= 'Kz';
if WordApplication1.ActiveDocument.Bookmarks.Exists(Bookmark) then
begin
QUserSql('Select * From "'+DBPath+DBUserName+'" WHERE BBenutzer Like "'+BenutzerName+'"');
R:= WordApplication1.ActiveDocument.Bookmarks.Item(Bookmark).Range;
R.InsertAfter(Form1.QUser.FieldByName('BKz').AsString);
end;
WordDocument1.SaveAs(FileName);
WordApplication1.Visible:= true;
WordDocument1.Disconnect;
end;
Ich habe dazu die Office-Komponenten verwenden (WordDocument und WordApplication).
Ich hoffe das hilft Dir weiter.
Gruß
Albi
|
|
Zitat
|