Einzelnen Beitrag anzeigen

Benutzerbild von matf
matf

Registriert seit: 14. Feb 2007
Ort: Amberg
28 Beiträge
 
Delphi 2009 Professional
 
#1

Word Datei via COM als neues Dokunment öffnen

  Alt 17. Jan 2009, 13:05
Hallo.

Ich habe folgendes Problem:
Ich möchte für eine Art Report-Ausgabe Werte an Word übergeben. Das ganze geht auch recht gut mit folgendem Code:
Delphi-Quellcode:
var
  FileName: OleVariant;
  vWhat, vBookmark, Marke: OleVariant;
begin
  FileName := ExtractFilePath(paramstr(0)) + 'marke.dot';
  WordApplication1.Connect;
  WordApplication1.Documents.OpenOld(FileName, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam);
  WordDocument1.ConnectTo(WordApplication1.ActiveDocument);
  WordApplication1.Visible := True;
  vWhat:=wdGoToBookmark;
  vBookmark:='adresse';
  //WordDocument1.Bookmarks.Item(vBookmark).Range.InsertAfter('test');

  if WordDocument1.Bookmarks.Exists(vBookmark) then
  begin
    Marke := WordDocument1.Bookmarks.Item(vBookmark).Range;
    Marke.InsertAfter(memAdresse.Text);
  end;
end;
Sorry, dass der Code so gruslig ist, aber das ist nur zum Testen.
Mein Problem ist nun, dass Word diese Dot-Datei öffnet und nicht ein neues, ungespeichertes Dokument draus macht. Wenn also jetzt der Anwender auf Speichern klickt, überschreibt er die Dot-Datei.
Wie kann ich das umgehen? Ich würde mir irgendwas vorstellen, dass eine Word-Datei geöffnet wird, aber wie eine neue Datei behandelt wird.
Geht das?

Danke,
Matthias
  Mit Zitat antworten Zitat