![]() |
Hilfe bei Word und Ole (Briefkopf)
Hi!
Mit folgendem Code möchte ich einen Briefkopf in Word erstellen:
Delphi-Quellcode:
Word öffnet sich zwar, aber in das dokument wird nix eingetragen. Das Programm zeigt
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; mir auch die Fehlermeldung. Was läuft da schief? |
Re: Hilfe bei Word und Ole (Briefkopf)
Hallo,
Das try...except hast du irgendwie falsch gesetzt... Setze doch mal Haltepunkte und Schritt fuer Schritt ausfuehren |
Re: Hilfe bei Word und Ole (Briefkopf)
Hi!
Ja du hast recht. Habe den Try except Block jetzt nach oben gepackt. Bekomme jetzt allerdings die Fehlermeldung, dass die Methode Active nicht vom Automationsobjekt unterstützt wird. Liegt das an der WordVersion(XP)? |
Re: Hilfe bei Word und Ole (Briefkopf)
Woher hast du denn den Code
Delphi-Quellcode:
??
word.Active.ActivePane
Muesste es nicht
Delphi-Quellcode:
heissen?
word.ActiveWindow.ActivePane
|
Re: Hilfe bei Word und Ole (Briefkopf)
Aus Delphi 3 für Profis. Kann natürlich sein, dass ich mich vertippt habe. :oops:
Ja war natürlich so. Schon dämlich, wenn man nicht mal abschreiben kann :wall: Danke... |
Re: Hilfe bei Word und Ole (Briefkopf)
Moin,
versuch doch mal folgendes
Delphi-Quellcode:
MfG
uses OleServer, WordXP;
procedure TForm.ButtonClick(Sender: TObject); var WordApplication:TWordApplication; type_:variant; begin WordApplication:=TWordApplication.Create(Self); try WordApplication.Connect; WordApplication.Visible:=true; WordApplication.Documents.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam); if WordApplication.ActiveWindow.View.SplitSpecial <> 0 then WordApplication.ActiveWindow.Panes.Item(2).Close; type_:=WordApplication.ActiveWindow.ActivePane.View.type_; if INTEGER(type_) in [1, 2, 3] then WordApplication.ActiveWindow.ActivePane.View.type_ := 3; WordApplication.ActiveWindow.ActivePane.View.SeekView := 9; WordApplication.Selection.Font.Name := 'Arial'; WordApplication.Selection.Font.Size := 12; WordApplication.Selection.Font.Bold := 1; WordApplication.Selection.ParagraphFormat.Alignment := 1; WordApplication.Selection.TypeText('Mustername - Musterstrasse 433 - 34223 Musterhausen'); if WordApplication.Selection.HeaderFooter.IsHeader then WordApplication.ActiveWindow.ActivePane.View.SeekView := 10 else WordApplication.ActiveWindow.ActivePane.View.SeekView := 9; WordApplication.Selection.TypeText('Bankverbindung sollte hier stehen'); WordApplication.ActiveWindow.ActivePane.View.SeekView := 0; WordApplication.Selection.TypeText(DBEdit2.Text + ' ' + DBEdit1.Text); WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeText(DBEdit3.Text + ' ' + DBEdit4.Text); WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.selection.Font.Name := 'Arial'; WordApplication.Selection.Font.Size := 12; WordApplication.Selection.Font.Bold := 1; WordApplication.Selection.TypeText(DBEdit5.Text + ' ' + DBEdit6.Text); WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.selection.Font.Name := 'Arial'; WordApplication.Selection.Font.Size := 12; WordApplication.Selection.Font.Bold := 1; WordApplication.Selection.TypeText('Betreff: '); WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.Selection.TypeParagraph; WordApplication.selection.Font.Name := 'Arial'; WordApplication.Selection.Font.Size := 12; WordApplication.Selection.Font.Bold := 1; WordApplication.Selection.TypeText('Sehr geehrte Damen und Herren,'); finally WordApplication.Disconnect; WordApplication.free; end; end; Thorsten |
Re: Hilfe bei Word und Ole (Briefkopf)
Danke! Funktioniert jetzt (beide Varianten).
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:10 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz