AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Hilfe bei Word und Ole (Briefkopf)

Ein Thema von Grolle · begonnen am 28. Jun 2005 · letzter Beitrag vom 29. Jun 2005
Antwort Antwort
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
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 28. Jun 2005, 23:24
Hallo,

Das try...except hast du irgendwie falsch gesetzt...
Setze doch mal Haltepunkte und Schritt fuer Schritt ausfuehren
Thomas
  Mit Zitat antworten Zitat
Grolle

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

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 28. Jun 2005, 23:34
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)?

  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#4

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 29. Jun 2005, 00:13
Woher hast du denn den Code

word.Active.ActivePane ??


Muesste es nicht

word.ActiveWindow.ActivePane heissen?
Thomas
  Mit Zitat antworten Zitat
Grolle

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

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 29. Jun 2005, 00:17
Aus Delphi 3 für Profis. Kann natürlich sein, dass ich mich vertippt habe.

Ja war natürlich so. Schon dämlich, wenn man nicht mal abschreiben kann

Danke...

  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 29. Jun 2005, 00:25
Moin,

versuch doch mal folgendes

Delphi-Quellcode:
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;
MfG
Thorsten
  Mit Zitat antworten Zitat
Grolle

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

Re: Hilfe bei Word und Ole (Briefkopf)

  Alt 29. Jun 2005, 00:36
Danke! Funktioniert jetzt (beide Varianten).

  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz