<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[OLE zugriff auf Word]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich besitze den Turbo C++ builder von Borland. von diesem will ich auf word darauf zugreifen das funktionier auch fast.</p>
<p>Das Problem ist das er nicht zu den Textmarken springt und diese ausfüllt sonder alles in die erste zeile schreibt.</p>
<p>Kann mir einer Helfen damit das funktioniert</p>
<p>Vielen dank im Vorraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Hier die CPP Datei</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;FormMain.h&quot;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
	: TForm(Owner)
{
}

//---------------------------------------------------------------------------
// Initialisierung des Word OLE-Servers
//---------------------------------------------------------------------------
bool __fastcall TfrmMain::InitOleServer(Variant &amp;vOLEWord)
{
  vOLEWord = Unassigned;
  try
  {
    // vielleicht läuft Word ja bereits (wenn nicht, wird hier
    // eine Exception generiert - aber die ist ja behandelt :)
    vOLEWord = GetActiveOleObject(&quot;Word.Application&quot;);
    return false;
  }
  catch(...)
  {
     try
     {
       // vielleicht läuft Word ja bereits...
       vOLEWord = CreateOleObject(&quot;Word.Application&quot;);
       return true;
     }
     catch(Exception&amp; e)
     {
        // Wahrscheinlich kein Word auf dem Rechner...
		Application-&gt;MessageBox(e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
        vOLEWord = Unassigned;
     }
  }
  return true;
}

//---------------------------------------------------------------------------
// Beenden des Word OLE-Servers
//---------------------------------------------------------------------------
void __fastcall TfrmMain::TerminateOleServer(Variant &amp;vOLEWord)
{
  // Word OLE-Server beenden:
  if(!vOLEWord.IsEmpty())
  {
    vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;Quit&quot;);
    vOLEWord = Unassigned;
  }
}

//---------------------------------------------------------------------------
// Word-Dokument erzeugen, ggf. speichern und/oder drucken
//---------------------------------------------------------------------------
void __fastcall TfrmMain::CreateDocument(Variant &amp;vOLEWord,
  AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint)
{
  try
  {
    // falls Word-Fenster sichtbar sein soll,
    // muss folgende Zeile aktiviert werden:
    // vOLEWord.OlePropertySet(&quot;Visible&quot;, true);

    // Falls die Vorlagen-Datei nicht existiert, schimpfen und beenden:
    if(!FileExists(slTemplateFile))
    {
      Application-&gt;MessageBox(&quot;Vorlagendatei nicht gefunden !&quot;,
        &quot;Abbruch&quot;,MB_ICONERROR);
      return;
    }

    // Referenz auf die &quot;Documents&quot;-Eigenschaft besorgen
    Variant vDokuments = vOLEWord.OlePropertyGet(&quot;Documents&quot;);
    // neues Dokument mit slTemplateFile als Dokumentenvorlage erzeugen:
    vDokuments.Exec(Procedure(&quot;Add&quot;) &lt;&lt; slTemplateFile &lt;&lt; 0);

    //--------------------------------------------------
    // Formular-Felder ausfüllen
    //--------------------------------------------------

    // Referenz auf die &quot;Selection&quot;-Eigenschaft besorgen
    Variant vSelection = vOLEWord.OlePropertyGet(&quot;Selection&quot;);

    // Zu Textmarke &quot;Empfaenger&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Empfaenger&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editEmpfaenger-&gt;Text.c_str()));

    // Zu Textmarke &quot;Anschrift&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Anschrift&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editAnschrift-&gt;Text.c_str()));

    // Zu Textmarke &quot;PLZ_Ort&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;PLZ_Ort&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editPLZ_Ort-&gt;Text.c_str()));

    // Zu Textmarke &quot;Betreff&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Betreff&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
     ((Variant)editBetreff-&gt;Text.c_str()));

    // Zu Textmarke &quot;Anrede&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Anrede&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editAnrede-&gt;Text.c_str()));

    // Zu Textmarke &quot;Text&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Text&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)memoText-&gt;Lines-&gt;Text.c_str()));

    // Zu Textmarke &quot;Ersteller&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Ersteller&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editErsteller-&gt;Text.c_str()));

    // ggf. drucken:
    if(blPrint)
      vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;PrintOut&quot;);

    // ggf. speichern:
    Variant vActiveDocument = vOLEWord.OlePropertyGet(&quot;ActiveDocument&quot;);
    if(slSaveFile != EmptyStr)
      vActiveDocument.Exec(Procedure(&quot;SaveAs&quot;) &lt;&lt; slSaveFile &lt;&lt; 0 &lt;&lt; 0
        &lt;&lt; &quot;&quot; &lt;&lt; 1 &lt;&lt; &quot;&quot; &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 );

    // &quot;gespeichert&quot;-Flag in Word setzen, damit keine Nachfragen kommen
    vActiveDocument.OlePropertySet(&quot;Saved&quot;, true);

    // Datei schließen:
    vActiveDocument.Exec(Procedure(&quot;Close&quot;));
  }
  catch(Exception&amp; e)
  {
    Application-&gt;MessageBox( e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
  }
}

//---------------------------------------------------------------------------
// Dokument erzeugen und speichern
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnCreateAndSaveDocClick(TObject *Sender)
{
  // OLE-Server initialisieren, die Variable blWordStarted
  // wird auf true gesetzt falls Word nicht bereits aktiv war
  Variant vOLEWord;
  bool blWordStarted = InitOleServer(vOLEWord);

  // Falls die Initialisierung des OLE-Servers erfolgreich,
  // Dokument erzeugen und speichern:
  if(!vOLEWord.IsEmpty())
    CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;vorlage.doc&quot;,
      ExtractFilePath(ParamStr(0))+&quot;Brief.doc&quot;, false);

  // Word nur beenden, wenn es von uns zuvor gestartet wurde:
  if(blWordStarted) TerminateOleServer(vOLEWord);
}

//---------------------------------------------------------------------------
// Dokument erzeugen und drucken
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnCreateAndPrintDocClick(TObject *Sender)
{
  // OLE-Server initialisieren, die Variable blWordStarted
  // wird auf true gesetzt falls Word nicht bereits aktiv war
  Variant vOLEWord;
  bool blWordStarted = InitOleServer(vOLEWord);

  // Falls die Initialisierung des OLE-Servers erfolgreich,
  // Dokument erzeugen und drucken:
  if(!vOLEWord.IsEmpty())
    CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;vorlage.doc&quot;,
      EmptyStr, true);
  // Word nur beenden, wenn es von uns zuvor gestartet wurde:
  if(blWordStarted) TerminateOleServer(vOLEWord);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Hier die H Datei</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#ifndef FormMainH
#define FormMainH
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
#include &lt;ComObj.hpp&gt;
#include &lt;utilcls.h&gt;

typedef enum WdGoToItem
{
  wdGoToBookmark = 0xFFFFFFFF, 
  wdGoToSection = 0, 
  wdGoToPage = 1, 
  wdGoToTable = 2, 
  wdGoToLine = 3, 
  wdGoToFootnote = 4, 
  wdGoToEndnote = 5, 
  wdGoToComment = 6, 
  wdGoToField = 7, 
  wdGoToGraphic = 8, 
  wdGoToObject = 9, 
  wdGoToEquation = 10, 
  wdGoToHeading = 11, 
  wdGoToPercent = 12, 
  wdGoToSpellingError = 13, 
  wdGoToGrammaticalError = 14, 
  wdGoToProofreadingError = 15
} WdGoToItem;

//---------------------------------------------------------------------------
class TfrmMain : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
  TButton *btnCreateAndSaveDoc;
	TEdit *editAnrede;
	TLabel *Label1;
  TEdit *editEmpfaenger;
	TLabel *Label2;
  TEdit *editAnschrift;
	TLabel *Label3;
	TLabel *Label4;
  TEdit *editPLZ_Ort;
  TLabel *lblBetreff;
  TEdit *editBetreff;
  TMemo *memoText;
	TLabel *Label6;
	TLabel *Label7;
  TEdit *editErsteller;
  TButton *btnCreateAndPrintDoc;
  void __fastcall btnCreateAndSaveDocClick(TObject *Sender);
  void __fastcall btnCreateAndPrintDocClick(TObject *Sender);
private:	// Anwender-Deklarationen

  // Initialisierung des Word OLE-Servers
  bool __fastcall InitOleServer(Variant &amp;vOLEWord);

  // Word-Dokument erzeugen, ggf. speichern und/oder drucken
  void __fastcall CreateDocument(Variant &amp;vOLEWord,AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint);

  // Beenden des Word OLE-Servers
  void __fastcall TerminateOleServer(Variant &amp;vOLEWord);

public:		// Anwender-Deklarationen
	__fastcall TfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/209078/ole-zugriff-auf-word</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 12:06:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209078.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Mar 2008 13:58:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to OLE zugriff auf Word on Wed, 26 Mar 2008 14:13:07 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich besitze den Turbo C++ builder von Borland. von diesem will ich auf word darauf zugreifen das funktionier auch fast.</p>
<p>Das Problem ist das er nicht zu den Textmarken springt und diese ausfüllt sonder alles in die erste zeile schreibt.</p>
<p>Kann mir einer Helfen damit das funktioniert</p>
<p>Vielen dank im Vorraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Hier die CPP Datei</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;FormMain.h&quot;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
	: TForm(Owner)
{
}

//---------------------------------------------------------------------------
// Initialisierung des Word OLE-Servers
//---------------------------------------------------------------------------
bool __fastcall TfrmMain::InitOleServer(Variant &amp;vOLEWord)
{
  vOLEWord = Unassigned;
  try
  {
    // vielleicht läuft Word ja bereits (wenn nicht, wird hier
    // eine Exception generiert - aber die ist ja behandelt :)
    vOLEWord = GetActiveOleObject(&quot;Word.Application&quot;);
    return false;
  }
  catch(...)
  {
     try
     {
       // vielleicht läuft Word ja bereits...
       vOLEWord = CreateOleObject(&quot;Word.Application&quot;);
       return true;
     }
     catch(Exception&amp; e)
     {
        // Wahrscheinlich kein Word auf dem Rechner...
		Application-&gt;MessageBox(e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
        vOLEWord = Unassigned;
     }
  }
  return true;
}

//---------------------------------------------------------------------------
// Beenden des Word OLE-Servers
//---------------------------------------------------------------------------
void __fastcall TfrmMain::TerminateOleServer(Variant &amp;vOLEWord)
{
  // Word OLE-Server beenden:
  if(!vOLEWord.IsEmpty())
  {
    vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;Quit&quot;);
    vOLEWord = Unassigned;
  }
}

//---------------------------------------------------------------------------
// Word-Dokument erzeugen, ggf. speichern und/oder drucken
//---------------------------------------------------------------------------
void __fastcall TfrmMain::CreateDocument(Variant &amp;vOLEWord,
  AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint)
{
  try
  {
    // falls Word-Fenster sichtbar sein soll,
    // muss folgende Zeile aktiviert werden:
    // vOLEWord.OlePropertySet(&quot;Visible&quot;, true);

    // Falls die Vorlagen-Datei nicht existiert, schimpfen und beenden:
    if(!FileExists(slTemplateFile))
    {
      Application-&gt;MessageBox(&quot;Vorlagendatei nicht gefunden !&quot;,
        &quot;Abbruch&quot;,MB_ICONERROR);
      return;
    }

    // Referenz auf die &quot;Documents&quot;-Eigenschaft besorgen
    Variant vDokuments = vOLEWord.OlePropertyGet(&quot;Documents&quot;);
    // neues Dokument mit slTemplateFile als Dokumentenvorlage erzeugen:
    vDokuments.Exec(Procedure(&quot;Add&quot;) &lt;&lt; slTemplateFile &lt;&lt; 0);

    //--------------------------------------------------
    // Formular-Felder ausfüllen
    //--------------------------------------------------

    // Referenz auf die &quot;Selection&quot;-Eigenschaft besorgen
    Variant vSelection = vOLEWord.OlePropertyGet(&quot;Selection&quot;);

    // Zu Textmarke &quot;Empfaenger&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Empfaenger&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editEmpfaenger-&gt;Text.c_str()));

    // Zu Textmarke &quot;Anschrift&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Anschrift&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editAnschrift-&gt;Text.c_str()));

    // Zu Textmarke &quot;PLZ_Ort&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;PLZ_Ort&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editPLZ_Ort-&gt;Text.c_str()));

    // Zu Textmarke &quot;Betreff&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Betreff&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
     ((Variant)editBetreff-&gt;Text.c_str()));

    // Zu Textmarke &quot;Anrede&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Anrede&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editAnrede-&gt;Text.c_str()));

    // Zu Textmarke &quot;Text&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Text&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)memoText-&gt;Lines-&gt;Text.c_str()));

    // Zu Textmarke &quot;Ersteller&quot; gehen:
    vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
       0 &lt;&lt; 0 &lt;&lt; &quot;Ersteller&quot;);
    // den Text aus dem Eingabefeld eintragen:
    vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
      ((Variant)editErsteller-&gt;Text.c_str()));

    // ggf. drucken:
    if(blPrint)
      vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;PrintOut&quot;);

    // ggf. speichern:
    Variant vActiveDocument = vOLEWord.OlePropertyGet(&quot;ActiveDocument&quot;);
    if(slSaveFile != EmptyStr)
      vActiveDocument.Exec(Procedure(&quot;SaveAs&quot;) &lt;&lt; slSaveFile &lt;&lt; 0 &lt;&lt; 0
        &lt;&lt; &quot;&quot; &lt;&lt; 1 &lt;&lt; &quot;&quot; &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 );

    // &quot;gespeichert&quot;-Flag in Word setzen, damit keine Nachfragen kommen
    vActiveDocument.OlePropertySet(&quot;Saved&quot;, true);

    // Datei schließen:
    vActiveDocument.Exec(Procedure(&quot;Close&quot;));
  }
  catch(Exception&amp; e)
  {
    Application-&gt;MessageBox( e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
  }
}

//---------------------------------------------------------------------------
// Dokument erzeugen und speichern
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnCreateAndSaveDocClick(TObject *Sender)
{
  // OLE-Server initialisieren, die Variable blWordStarted
  // wird auf true gesetzt falls Word nicht bereits aktiv war
  Variant vOLEWord;
  bool blWordStarted = InitOleServer(vOLEWord);

  // Falls die Initialisierung des OLE-Servers erfolgreich,
  // Dokument erzeugen und speichern:
  if(!vOLEWord.IsEmpty())
    CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;vorlage.doc&quot;,
      ExtractFilePath(ParamStr(0))+&quot;Brief.doc&quot;, false);

  // Word nur beenden, wenn es von uns zuvor gestartet wurde:
  if(blWordStarted) TerminateOleServer(vOLEWord);
}

//---------------------------------------------------------------------------
// Dokument erzeugen und drucken
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnCreateAndPrintDocClick(TObject *Sender)
{
  // OLE-Server initialisieren, die Variable blWordStarted
  // wird auf true gesetzt falls Word nicht bereits aktiv war
  Variant vOLEWord;
  bool blWordStarted = InitOleServer(vOLEWord);

  // Falls die Initialisierung des OLE-Servers erfolgreich,
  // Dokument erzeugen und drucken:
  if(!vOLEWord.IsEmpty())
    CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;vorlage.doc&quot;,
      EmptyStr, true);
  // Word nur beenden, wenn es von uns zuvor gestartet wurde:
  if(blWordStarted) TerminateOleServer(vOLEWord);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Hier die H Datei</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#ifndef FormMainH
#define FormMainH
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
#include &lt;ComObj.hpp&gt;
#include &lt;utilcls.h&gt;

typedef enum WdGoToItem
{
  wdGoToBookmark = 0xFFFFFFFF, 
  wdGoToSection = 0, 
  wdGoToPage = 1, 
  wdGoToTable = 2, 
  wdGoToLine = 3, 
  wdGoToFootnote = 4, 
  wdGoToEndnote = 5, 
  wdGoToComment = 6, 
  wdGoToField = 7, 
  wdGoToGraphic = 8, 
  wdGoToObject = 9, 
  wdGoToEquation = 10, 
  wdGoToHeading = 11, 
  wdGoToPercent = 12, 
  wdGoToSpellingError = 13, 
  wdGoToGrammaticalError = 14, 
  wdGoToProofreadingError = 15
} WdGoToItem;

//---------------------------------------------------------------------------
class TfrmMain : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
  TButton *btnCreateAndSaveDoc;
	TEdit *editAnrede;
	TLabel *Label1;
  TEdit *editEmpfaenger;
	TLabel *Label2;
  TEdit *editAnschrift;
	TLabel *Label3;
	TLabel *Label4;
  TEdit *editPLZ_Ort;
  TLabel *lblBetreff;
  TEdit *editBetreff;
  TMemo *memoText;
	TLabel *Label6;
	TLabel *Label7;
  TEdit *editErsteller;
  TButton *btnCreateAndPrintDoc;
  void __fastcall btnCreateAndSaveDocClick(TObject *Sender);
  void __fastcall btnCreateAndPrintDocClick(TObject *Sender);
private:	// Anwender-Deklarationen

  // Initialisierung des Word OLE-Servers
  bool __fastcall InitOleServer(Variant &amp;vOLEWord);

  // Word-Dokument erzeugen, ggf. speichern und/oder drucken
  void __fastcall CreateDocument(Variant &amp;vOLEWord,AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint);

  // Beenden des Word OLE-Servers
  void __fastcall TerminateOleServer(Variant &amp;vOLEWord);

public:		// Anwender-Deklarationen
	__fastcall TfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1480646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480646</guid><dc:creator><![CDATA[freak83]]></dc:creator><pubDate>Wed, 26 Mar 2008 14:13:07 GMT</pubDate></item></channel></rss>