Autor Beitrag
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Fr 21.02.03 16:36 
Mit dieser Procedure kann man ganz einfach einen Word Serienbrief erstellen!

Parameter:
  • Titel:TRichEdit
    enthält den Titel das Serienbriefes
  • DBQuelle:String
    enthält den Pfad zur dbf Datenbank
  • DBFelder: TStringlist
    enhält alle Feldnamen der Datenbank, welche für den Serienbrief benötigt werden
  • VertAbstand: Integer
    Bestimmt die vertikale Cursorausrichtung (in Zeilenumbrüchen)
  • HorAbstand: Integer
    Bestimmt die horizontale Cursorausrichtung (in Leerzeichen)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
Procedure MachEinSerienBrief(Titel:TRichEdit; DBQuelle: String; DBFelder:TStringlist; VertAbstand: Integer; HorAbstand: Integer); 
var 
  Word: OLEVariant; 
  i:integer; 
  SHorAbstand:String
begin 
  try                                                                          
    WordApp:=GetActiveOleObject('Word.Application');                          
  except                                            
    try                                              
      WordApp:=CreateOleObject('Word.Application');                    
    except                                    
      ShowMessage('Microsoft Word kann nicht starten.');                    
      screen.cursor:=crDefault;                
      exit;                                                
    end;                                                  
  end;            
  Word.ActiveDocument.MailMerge.MainDocumentType:= wdFormLetters; 
  titel.SelectAll; 
  titel.CopyToClipboard; 
  Word.Selection.paste; 
  word.ActiveDocument.MailMerge.OpenDataSource(DBQuelle,'SELECT * FROM [" '+ DBQuelle +' "]"'); 
  Word.ActiveDocument.MailMerge.EditMainDocument; 
  for i:=0 to VertAbstand do 
  begin 
    Word.Selection.TypeParagraph; 
  end
  SHorAbstand:=''
  for i:=0 to HorAbstand do 
  begin 
    SHorAbstand:=SHorAbstand+' '
  end
  for i:=0 to DBFelder.Count-1 do 
  begin 
    Word.Selection.TypeText(SHorAbstand); 
    Word.ActiveDocument.MailMerge.Fields.Add(Word.Selection.Range,DBFelder.Strings[i]); 
    Word.Selection.TypeParagraph; 
  end
  Word := Unassigned; 
end;


Viel Spass damit Greez Cyrus
Copyright by Cyrus!!