Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Ole Excel - wie kann ich Textmarken ansprechen (https://www.delphipraxis.net/3753-ole-excel-wie-kann-ich-textmarken-ansprechen.html)

[TP]Hawk274 28. Mär 2003 14:44


Ole Excel - wie kann ich Textmarken ansprechen
 
Ich habe ich meinem Worddokument mehrere Textmarken gesetzt. Diese möchte ich nun über Ole ansprechen, aber ich komm nicht rauf wie.
Leider finde ich auch keine gute Dokumentation über dieses OLE. Wenn dann nur teilweise veraltete Dokumentation zu WinWord97.
Ich benutzte Winword2000!

Helld_River 28. Mär 2003 15:21

http://www.delphi-treff.de/content/t...dex.php4?kat=3

einfach mal googlen :-)

Und was Word97 lann, das kann word2000 schon lange *g*

Gruß, Helld

[TP]Hawk274 28. Mär 2003 15:44

Zitat:

Und was Word97 lann, das kann word2000 schon lange *g*
Eben nicht :shock:, das ist das dumme daran.
Delphi-Quellcode:
vWhat:=wdGoToBookmark;
vBookmark:='BerichtsNr';
Word.Selection.GoTo_(vWhat, EmptyParam, EmptyParam, vBookmark);
Als Fehlermeldung kommt jedenfalls immer:
Die Methode 'GoTo_' wird vom Automatisierungsobjekt nicht unterstützt.

Habe dann aber einfach mal den Unterstrich weggenommen und siehe da es klappt. Also nichts da was unter Word97 geht, das funktioniert auch unter Word2000. :wink:

toms 28. Mär 2003 17:29

Hi,

Die Textmarken mit wdGoToBookmark anzusprechen ist eine Möglichkeit.
Es ist aber - so habe ich gehört - manchmal nicht so zuverlässig.
Andere Möglichkeit: Die Textmarken über das Bookmarks-Range anzusprechen.

Hier mal ein kleines Beispiel:


Code:
uses
  ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  BookmarkName, Doc, WordApp, R: OleVariant;
begin

  // Word Instanz Starten
  try
    WordApp := CreateOleObject('Word.Application');
  except
    ShowMessage('Could not start Word !');
    Exit;
  end;

  // Dok. öffnen
  WordApp.Documents.Open('c:\titel.doc');
  Doc := WordApp.ActiveDocument;

  // Name der Textmarke
  BookmarkName := 'DeineTextMarke';
  // Überprüfen, ob Textmarke vorhanden
  if Doc.Bookmarks.Exists(BookmarkName) then
  begin
    R := Doc.Bookmarks.Item(BookmarkName).Range;
    // Text bei Textmarke einfügen
    R.InsertAfter('Text bei Textmarke');
    R.Font.Color := clRed;
  end;
  // Dokument Speichern und Word beenden.
  if not VarIsEmpty(WordApp) then
  begin
    WordApp.DisplayAlerts := 0;
    WordApp.Documents.Item(1).Save;
    WordApp.Quit;
    BookmarkName := Unassigned;
    R := Unassigned;
    WordApp := Unassigned;
  end;
end;


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