Einzelnen Beitrag anzeigen

Grolle

Registriert seit: 5. Nov 2004
Ort: Coesfeld
1.268 Beiträge
 
Delphi 2010 Professional
 
#1

Hilfe bei Word und Ole (Briefkopf)

  Alt 28. Jun 2005, 23:13
Hi!
Mit folgendem Code möchte ich einen Briefkopf in Word erstellen:
Delphi-Quellcode:
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  try
    word := CreateOleObject('Word.Application');
    word.visible := true;
    word.Documents.Add;
      if word.ActiveWindow.View.SplitSpecial <> 0 then word.ActiveWindow.Panes[2].Close;
      if (word.Active.ActivePane.View.Type = 1) or
         (word.Active.ActivePane.View.Type = 2) or
         (word.Active.ActivePane.View.Type = 3) then
         word.ActiveWindow.ActivePane.View.Type := 3;
         word.ActiveWindow.ActivePane.View.SeekView := 9;
         word.selection.Font.Name := 'Arial';
         word.Selction.Font.Size := '12';
         word.Selection.Font.Bold := true;
         word.Selection.ParagraphFormat.Alignment := 1;
         word.Selection.TypeText(Text := 'Mustername - Musterstrasse 433 - 34223 Musterhausen');
         if word.selection.HeaderFooter.IsHeader = true then
            word.ActiveWindow.ActivePane.View.SeekView := 10
         else
            word.ActiveWindow.ActivePane.View.SeekView := 9;
            word.Selection.TypeText(Text := 'Bankverbindung sollte hier stehen');
         word.ActiveWindow.ActivePane.View.SeekView := 0;
         word.Selection.TypeText(Text := DBEdit2.Text + ' ' + DBEdit1.Text);
         word.Selection.TypeParagraph;
         word.Selection.TypeText(Text := DBEdit3.Text + ' ' + DBEdit4.Text);
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.selection.Font.Name := 'Arial';
         word.Selction.Font.Size := '12';
         word.Selection.Font.Bold := true;
         word.Selection.TypeText(Text := DBEdit5.Text + ' ' + DBEdit6.Text);
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.selection.Font.Name := 'Arial';
         word.Selction.Font.Size := '12';
         word.Selection.Font.Bold := true;
         word.Selection.TypeText(Text := 'Betreff: ');
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.Selection.TypeParagraph;
         word.selection.Font.Name := 'Arial';
         word.Selction.Font.Size := '12';
         word.Selection.Font.Bold := true;
         word.Selection.TypeText(Text := 'Sehr geehrte Damen und Herren,');
  except
    MessageDlg(' Word konnte nicht gestartet werden! ',mtError,[mbOK],0);
  end;
end;
Word öffnet sich zwar, aber in das dokument wird nix eingetragen. Das Programm zeigt
mir auch die Fehlermeldung. Was läuft da schief?

  Mit Zitat antworten Zitat