Hallo
Ich möchte mit Delphi einen Serien-Dokument-Vorlage schreiben.
Habe diesen Code aus dem Forum. Aber es geht nicht oder ich mache was falsch.
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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Word97, OleServer, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; WordApplication1: TWordApplication; WordDocument1: TWordDocument; procedure Button1Click(Sender: TObject); private public end;
var Form1: TForm1;
implementation
{$R *.DFM}
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject); const YourWordDocument = 'c:\test\worddoc.doc'; var BookmarkName, Doc, R: OleVariant; begin try except ShowMessage('keine Verbindung zur MS Word!'); end; WordApplication1.Connect; WordApplication1.Documents.Open(YourWordDocument); Doc := WordApp.ActiveDocument;
BookmarkName := 'Marke';
if Doc.Bookmarks.Exists(BookmarkName) then begin R := Doc.Bookmarks.Item(BookmarkName).Range; R.InsertAfter('Text bei Textmarke'); R.Font.Color := clRed; end;
if not VarIsEmpty(WordApp) then begin WordApp.DisplayAlerts := 0; WordApp.Documents.Item(1).Save; WordApp.Quit; BookmarkName := Unassigned; R := Unassigned; WordApp := Unassigned; end; end;
end. |
Ich bekomme also hier die Fehlermeldung:
[Fehler] Unit1.pas(42): Inkompatible Typen: 'TWordApplication' und 'IDispatch'
[Fehler] Unit1.pas(49): Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen
Es gibt mehrere Optionen Word anzusprechen doch bis jetzt hatte ich kein Glück.
Hatt einer eventuell nen Tip was ich hier ändern sollte