![]() |
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! |
![]() einfach mal googlen :-) Und was Word97 lann, das kann word2000 schon lange *g* Gruß, Helld |
Zitat:
Delphi-Quellcode:
Als Fehlermeldung kommt jedenfalls immer:
vWhat:=wdGoToBookmark;
vBookmark:='BerichtsNr'; Word.Selection.GoTo_(vWhat, EmptyParam, EmptyParam, vBookmark); 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: |
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