Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Suchen und Ersetzen in Word Dokument (https://www.delphipraxis.net/71946-suchen-und-ersetzen-word-dokument.html)

nezumi 22. Jun 2006 19:02


Suchen und Ersetzen in Word Dokument
 
Ich schon wieder....

Ich will in einem Word Dokument den Text "01." (kommt paar hundertmal vor) durch "Januar" ersetzen:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Word2000, OleServer, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    WordApplication1: TWordApplication;
    WordDocument1: TWordDocument;
    WordFont1: TWordFont;
    WordParagraphFormat1: TWordParagraphFormat;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
Form1: TForm1;
FileName: OleVariant;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
WordApplication1.Connect;
FileName := 'e:\Delphi\Word\01.doc';
WordApplication1.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordApplication1.visible := true;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
vAlt, vNeu: Variant;
begin
WordDocument1.ConnectTo(WordApplication1.ActiveDocument);
vAlt := '01.';
vNeu := 'Januar';
WordApplication1.Selection.Find.Execute(vAlt,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,
vNeu,EmptyParam);
end;

end.
Warum funzt das nicht???

Vielen Dank schonmal...

Luckie 22. Jun 2006 19:12

Re: Suchen und Ersetzen in Word Dokument
 
Zitat:

Zitat von nezumi
Warum funzt das nicht???

eine etwas präzisere Fehlerbeschreibung wäre betsimmt hilfreich.

nezumi 22. Jun 2006 19:46

Re: Suchen und Ersetzen in Word Dokument
 
beim Compilieren kommen folgende Fehlermeldungen:

Zur Zeile

WordApplication1.Selection.Find.Execute(vAlt,Empty Param,... //usw

"Types of actual and formal var parameters must be identical"
"Not enough actual parameters"

omata 22. Jun 2006 19:54

Re: Suchen und Ersetzen in Word Dokument
 
Schau doch mal hier

nezumi 22. Jun 2006 20:06

Re: Suchen und Ersetzen in Word Dokument
 
Hallo omata,

danke, das hatte ich auch schon gefunden, da sind aber zu viele Sachen drin, die ich nicht verstehe. Ich will Automation lernen und daher auch wissen, was ich mache und warum was funktioniert oder nicht.

Gruß,


Alle Zeitangaben in WEZ +1. Es ist jetzt 22: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