<?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[Word&#x2F;Excel automation in VC++ ohne MFC und #import]]></title><description><![CDATA[<p>Hallo,<br />
ich bin gerade dabei eine Applikation in VC++ zu schreiben, welche über<br />
OLE auf MS Word zugreift.</p>
<p>Ich erstelle über &quot;Word.Application&quot; eine Instance auf MS Word und öffne dort ein Dokument.</p>
<pre><code class="language-cpp">CLSID clsidWordApplication;
HRESULT hr = CLSIDFromProgID(L&quot;Word.Application&quot;, &amp;clsidWordApplication);

IDispatchPtr spIWord = NULL;
// Word - Application erzeugen:
hr = CoCreateInstance(clsidWordApplication, NULL, CLSCTX_SERVER, ID_IDispatch, (void **) (IDispatch *) &amp;spIWord);

//Zugriff auf Datein-Objekt
DISPID dispidDocuments = 0;
hr = m_pDispWord-&gt;GetIDOfName(L&quot;Documents&quot;, &amp;dispidDocuments);
hr = m_pDispWord-&gt;GetProperty(dispidDocuments, &amp;vResult);
CComDispatchDriver spDocuments(vResult.pdispVal);

//Öffnen der Datei
hr = spDocuments.Invoke1(L&quot;Open&quot;, &amp;vFilename, &amp;vResult);
</code></pre>
<p>Nun ist es so das in diesem Word-Dokument auch Excel-Tabellen eingebettet sind.</p>
<p>Ich möchte nun solch eine Tabelle bearbeiten.<br />
Dafür hole ich mir diese Tabell als OLE-Object.</p>
<pre><code class="language-cpp">//OLEFormat
IDispatchPtr spOLEFormat = NULL;
hr = spDispShape.GetPropertyByName(L&quot;OLEFormat&quot;, &amp;vResult);
spOLEFormat = vResult.pdispVal;
CComDispatchDriver spDispOLEFormat(spOLEFormat);

//OLE-Object aktivieren
hr = spDispOLEFormat.Invoke0(L&quot;Activate&quot;, &amp;vResult);

//OLEObject holen
IDispatchPtr spOLEObject = NULL;
hr = spDispOLEFormat.GetPropertyByName(L&quot;Object&quot;, &amp;vResult);
spOLEObject = vResult.pdispVal;
CComDispatchDriver spDispOLEObject(spOLEObject);

//Worksheet holen
IDispatchPtr spActiveSheet = NULL;
hr = spDispOLEObject.GetPropertyByName(L&quot;ActiveSheet&quot;, &amp;vResult);
spActiveSheet = vResult.pdispVal;
CComDispatchDriver spDispActiveSheet(spActiveSheet);
</code></pre>
<p>Nun möchte ich die Werte in den einzelnen Zellen ändern.</p>
<p>Dafür holle ich mir über Range die Zelle.</p>
<pre><code class="language-cpp">DispatchPtr spColumns = NULL;
VARIANT vRangeExcel1, vRangeExcel2;
vRangeExcel1.vt =VT_BSTR;
vRangeExcel1.bstrVal = L&quot;A1&quot;;	
vRangeExcel2.vt =VT_BSTR;
vRangeExcel2.bstrVal = L&quot;A1&quot;;	
hr = spDispActiveSheet.Invoke2(L&quot;Range&quot;, &amp;vRangeExcel1, &amp;vRangeExcel2, &amp;vResult);
</code></pre>
<p>Leider bekomme ich hier aber immer die Meldung<br />
<em>0x80020003 Mitglied nicht gefunden.</em></p>
<p>Kann mir da jemand weiterhelfen bzw. mir sagen wo ich im Netz dazu Hilfe finde (ausser MSDN).</p>
<p>Danke<br />
Friedl</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/69100/word-excel-automation-in-vc-ohne-mfc-und-import</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 06:45:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/69100.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Mar 2004 13:03:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Word&#x2F;Excel automation in VC++ ohne MFC und #import on Wed, 24 Mar 2004 13:09:23 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich bin gerade dabei eine Applikation in VC++ zu schreiben, welche über<br />
OLE auf MS Word zugreift.</p>
<p>Ich erstelle über &quot;Word.Application&quot; eine Instance auf MS Word und öffne dort ein Dokument.</p>
<pre><code class="language-cpp">CLSID clsidWordApplication;
HRESULT hr = CLSIDFromProgID(L&quot;Word.Application&quot;, &amp;clsidWordApplication);

IDispatchPtr spIWord = NULL;
// Word - Application erzeugen:
hr = CoCreateInstance(clsidWordApplication, NULL, CLSCTX_SERVER, ID_IDispatch, (void **) (IDispatch *) &amp;spIWord);

//Zugriff auf Datein-Objekt
DISPID dispidDocuments = 0;
hr = m_pDispWord-&gt;GetIDOfName(L&quot;Documents&quot;, &amp;dispidDocuments);
hr = m_pDispWord-&gt;GetProperty(dispidDocuments, &amp;vResult);
CComDispatchDriver spDocuments(vResult.pdispVal);

//Öffnen der Datei
hr = spDocuments.Invoke1(L&quot;Open&quot;, &amp;vFilename, &amp;vResult);
</code></pre>
<p>Nun ist es so das in diesem Word-Dokument auch Excel-Tabellen eingebettet sind.</p>
<p>Ich möchte nun solch eine Tabelle bearbeiten.<br />
Dafür hole ich mir diese Tabell als OLE-Object.</p>
<pre><code class="language-cpp">//OLEFormat
IDispatchPtr spOLEFormat = NULL;
hr = spDispShape.GetPropertyByName(L&quot;OLEFormat&quot;, &amp;vResult);
spOLEFormat = vResult.pdispVal;
CComDispatchDriver spDispOLEFormat(spOLEFormat);

//OLE-Object aktivieren
hr = spDispOLEFormat.Invoke0(L&quot;Activate&quot;, &amp;vResult);

//OLEObject holen
IDispatchPtr spOLEObject = NULL;
hr = spDispOLEFormat.GetPropertyByName(L&quot;Object&quot;, &amp;vResult);
spOLEObject = vResult.pdispVal;
CComDispatchDriver spDispOLEObject(spOLEObject);

//Worksheet holen
IDispatchPtr spActiveSheet = NULL;
hr = spDispOLEObject.GetPropertyByName(L&quot;ActiveSheet&quot;, &amp;vResult);
spActiveSheet = vResult.pdispVal;
CComDispatchDriver spDispActiveSheet(spActiveSheet);
</code></pre>
<p>Nun möchte ich die Werte in den einzelnen Zellen ändern.</p>
<p>Dafür holle ich mir über Range die Zelle.</p>
<pre><code class="language-cpp">DispatchPtr spColumns = NULL;
VARIANT vRangeExcel1, vRangeExcel2;
vRangeExcel1.vt =VT_BSTR;
vRangeExcel1.bstrVal = L&quot;A1&quot;;	
vRangeExcel2.vt =VT_BSTR;
vRangeExcel2.bstrVal = L&quot;A1&quot;;	
hr = spDispActiveSheet.Invoke2(L&quot;Range&quot;, &amp;vRangeExcel1, &amp;vRangeExcel2, &amp;vResult);
</code></pre>
<p>Leider bekomme ich hier aber immer die Meldung<br />
<em>0x80020003 Mitglied nicht gefunden.</em></p>
<p>Kann mir da jemand weiterhelfen bzw. mir sagen wo ich im Netz dazu Hilfe finde (ausser MSDN).</p>
<p>Danke<br />
Friedl</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487644</guid><dc:creator><![CDATA[wfriedl]]></dc:creator><pubDate>Wed, 24 Mar 2004 13:09:23 GMT</pubDate></item><item><title><![CDATA[Reply to Word&#x2F;Excel automation in VC++ ohne MFC und #import on Wed, 24 Mar 2004 13:49:27 GMT]]></title><description><![CDATA[<p>Was hat das mit C++ zu tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487703</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Wed, 24 Mar 2004 13:49:27 GMT</pubDate></item><item><title><![CDATA[Reply to Word&#x2F;Excel automation in VC++ ohne MFC und #import on Wed, 24 Mar 2004 14:41:29 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=1" rel="nofollow">MFC mit dem Visual C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/487798</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487798</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Wed, 24 Mar 2004 14:41:29 GMT</pubDate></item></channel></rss>