Wordapplication: Textmarke lokalisieren und ersetzen



  • Hallo,

    Ich bin gerade dabei ein Programm zu schreiben, dass Textmarken aus Word ersetzt, und danach das Dokument druckt.
    Momentan bin ich so weit, dass mein Programm eine Verbindung zu Word aufbaut, ein Dokument läd und anzeigt.
    In dem Dokument ist die Textmarke "eins" enthalten, die auch angezeigt wird.
    Für Tipps wie ich die Textmarke anspreche und ersetzte wäre ich sehr dankbar.

    OleVariant Filename;
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
          if (OpenDialog1->Execute())
            Filename = OpenDialog1->FileName;
          else
            exit(1);
    
          WordApplication1->Connect();      //Verbindung zu Word
    
          WordApplication1->Documents->OpenOld(Filename, EmptyParam, EmptyParam,      //das Dokument öffnen
                                         EmptyParam, EmptyParam, EmptyParam,
                                         EmptyParam, EmptyParam, EmptyParam,
                                         EmptyParam);
    
          WordDocument1->ConnectTo(WordApplication1->ActiveDocument);
          WordApplication1->Visible = True;                                //Word wird sichtbar}
    }
    

    Grüße

    Jörg Nitsche



  • Hallo,

    Ich habe etwas gefunden, was das macht was ich möchte:

    TVariant bookmark = "eins";
          TVariant what(wdGoToBookmark);
    
          WordApplication1->Selection->GoTo(what, EmptyParam, EmptyParam, bookmark);
          WordApplication1->Selection->set_Text(WideString("Test"));
    

    Jetzt bekomme ich aber den Fehler:
    [C++ Error] Unit1.cpp(48): E2285 Could not find a match for 'Selection::GoTo(TVariant,OleVariant,OleVariant,TVariant)'

    Woran kann das liegen?



  • Hallo

    wenn du unbedingt mit dem Word Ole-Server arbeiten willst : schau mal in der VBA-Hilfe zu Word (nicht der Word-Hilfe selber) nach, unter Application.Selection.Find

    bis bald
    akari


Anmelden zum Antworten