Hallo,
Ich habe sowas wie eine Adress Datenbank in der ich die Adressen eingebe die in einer INI Datei gespeichert werden.
Die Adressen kann ich mir in den Programm in einer Listbox ausgeben lassen,
wobei noch die Funktion Serienbrief fehlt.
Einen Normalen Brief mach ich mit folgender Funktion:
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: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
| procedure TForm2.Button1Click(Sender: TObject); var Word: OLEVariant;
begin try Word := CreateOleObject('Word.Application'); except ShowMessage('Word kann nicht geöffnet werden!'); Exit; end; Word.Visible := True; Word.Documents.Add; if Word.ActiveWindow.View.SplitSpecial <> 0 then Word.ActiveWindow.Panes[2].Close; if (Word.ActiveWindow.ActivePane.View.type = 1) or (Word.ActiveWindow.ActivePane.View.type = 2) or (Word.ActiveWindow.ActivePane.View.type = 5) then Word.ActiveWindow.ActivePane.View.type := 3; Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True; Word.Selection.ParagraphFormat.Alignment := 2; Word.Selection.TypeText(FormatDateTime('dd.mm.yyyy', Now)); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True;
if Word.Selection.HeaderFooter.IsHeader = True then Word.ActiveWindow.ActivePane.View.SeekView := 10 else Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.ActiveWindow.ActivePane.View.SeekView := 0; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := true; Word.Selection.TypeText(Text := Edit3.Text + ' ' + edit2.Text); Word.Selection.TypeParagraph; Word.Selection.TypeText(Text := edit4.Text); Word.Selection.TypeParagraph;
Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := true;
Word.Selection.TypeText(Text := edit5.Text ); Word.Selection.TypeParagraph; Word.Selection.TypeText(Text := edit6.Text); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Arial'; Word.Selection.Font.Size := 14; Word.Selection.Font.Bold := True; Word.Selection.TypeText(Text := Combobox1.Text); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True; if radiogroup1.ItemIndex = 0 then Word.Selection.TypeText(Text := 'Sehr geehrter Herr ' + edit3.Text+','+#13#10+#13#10) else Word.Selection.TypeText(Text := 'Sehr geehrte Frau ' + edit3.Text+','+#13#10+#13#10) end; |
Jetzt dachte ich mach ich es beim Serienbrief genauso nur setz ich davor noch folgenden Code:
Delphi-Quelltext
1: 2: 3:
| for I:=Listbox1.Items.Count-1 downto 0 do begin if Listbox1.Selected[I] then |
Der Code sieht dann so aus:
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: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84:
| procedure TForm2.Button6Click(Sender: TObject); var I: Integer; Word: OLEVariant; begin
try Word := CreateOleObject('Word.Application'); except ShowMessage('Word kann nicht geöffnet werden!'); Exit; end; for I:=Listbox1.Items.Count-1 downto 0 do begin if Listbox1.Selected[I] then Word.Visible := True; Word.Documents.Add; if Word.ActiveWindow.View.SplitSpecial <> 0 then Word.ActiveWindow.Panes[2].Close; if (Word.ActiveWindow.ActivePane.View.type = 1) or (Word.ActiveWindow.ActivePane.View.type = 2) or (Word.ActiveWindow.ActivePane.View.type = 5) then Word.ActiveWindow.ActivePane.View.type := 3; Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True; Word.Selection.ParagraphFormat.Alignment := 2; Word.Selection.TypeText(FormatDateTime('dd.mm.yyyy', Now)); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True;
if Word.Selection.HeaderFooter.IsHeader = True then Word.ActiveWindow.ActivePane.View.SeekView := 10 else Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.ActiveWindow.ActivePane.View.SeekView := 0; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := true; Word.Selection.TypeText(Text := Edit3.Text + ' ' + edit2.Text); Word.Selection.TypeParagraph; Word.Selection.TypeText(Text := edit4.Text); Word.Selection.TypeParagraph;
Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := true;
Word.Selection.TypeText(Text := edit5.Text ); Word.Selection.TypeParagraph; Word.Selection.TypeText(Text := edit6.Text); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Arial'; Word.Selection.Font.Size := 14; Word.Selection.Font.Bold := True; Word.Selection.TypeText(Text := Combobox1.Text); Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.TypeParagraph; Word.Selection.Font.Name := 'Times New Roman'; Word.Selection.Font.Size := 12; Word.Selection.Font.Bold := True; if radiogroup1.ItemIndex = 0 then Word.Selection.TypeText(Text := 'Sehr geehrter Herr ' + edit3.Text+','+#13#10+#13#10) else Word.Selection.TypeText(Text := 'Sehr geehrte Frau ' + edit3.Text+','+#13#10+#13#10) end; |
Vom Lösungsweg her denke ich mir das ich die erste Markierte Adresse öffnen muss, drucken und wieder Freigeben und dann die liste der Reihe nach durcharbeiten.
Aber wie genau mach ich das?
Wenn ich jetzt in meiner INI Datei 100 Adressen drin habe, wird 100 Mal Word geöffnet mit nur einer Adresse.
Ich denke mal da fehlt noch die Zuweisung das er die Liste mit den Markierten Adressen der Reihe nach durcharbeiten soll.
Kann ich es mit der Variable [I] machen?
Wenn ja kann mir vllt wer sagen wo die hin muss?
Wenn ich komplett falsch liege, könntet ihr mir dann ein bisschen Hilfestellung geben?
Gruß