<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>North Atlanta Web Design &#187; Visual Studio 2008</title>
	<atom:link href="https://www.northatlantawebdesign.com/index.php/category/visual-studio-2008/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.northatlantawebdesign.com</link>
	<description>Programming Examples, Samples, and Tutorials</description>
	<lastBuildDate>Mon, 15 Aug 2011 20:18:35 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.7.41</generator>
	<item>
		<title>Automating Excel 2007 in C++ by Importing the Excel 2007 Type Library</title>
		<link>https://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/</link>
		<comments>https://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 16:58:51 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Gibeau]]></dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft Excel 2007]]></category>
		<category><![CDATA[Microsoft Office 2007]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Automating]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Excel 2007]]></category>
		<category><![CDATA[Type Library]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=119</guid>
		<description><![CDATA[When I started trying to write automations for Excel 2007 using C++, I ran into problems right up front. I was trying to use #import to get to the type library for Excel 2007, and was importing what I thought was the correct file. The following was written for a C++ application in Visual Studio [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>When I started trying to write automations for <a type="amzn">Excel 2007</a> using <a type="amzn">C++</a>, I ran into problems right up front.  I was trying to use #import to get to the type library for Excel 2007, and was importing what I thought was the correct file.  The following was written for a C++ application in <a type="amzn">Visual Studio 2008</a> (VS2008), automating Excel 2007.<br />
<span id="more-119"></span></p>
<ol>
<li>The Excel Type Library is not contained in XL5EN32.OLB as you might expect, it is contained in excel.exe</li>
<li>
Error #2: Even importing the correct file, errors were being raised.</p>
<pre class="brush: cpp; title: ; notranslate">
//The Following Import gives you the error Error	1	error C2504: '_IMsoDispObj' : base class undefined
#import &quot;C:\Program Files\Microsoft Office\Office12\EXCEL.EXE&quot;
</pre>
<p>To correctly import the Excel type library, two more references are needed: MSO.DLL and VBE6EXT.OLB</p>
<pre class="brush: cpp; title: ; notranslate">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll&quot; no_implementation raw_interfaces_only
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation raw_interfaces_only
#import &quot;C:\Program Files\Microsoft Office\OFFICE12\excel.exe&quot; no_implementation raw_interfaces_only
</pre>
</li>
<li>While this solved the problem of the _IMsoDispObj, it raised a few more issues.
<pre class="brush: cpp; title: ; notranslate">
warning C4003: not enough actual parameters for macro 'RGB'
warning C4003: not enough actual parameters for macro 'DialogBoxW'
</pre>
<p>Finally I had the solution, renaming the objects in question that seemed to be redefined elsewhere.</p>
<pre class="brush: cpp; title: ; notranslate">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL&quot; no_implementation rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;DocumentProperties&quot;, &quot;ExclDocumentProperties&quot;) rename(&quot;SearchPath&quot;, &quot;ExclSearchPath&quot;)
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation
#import &quot;D:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE&quot; rename(&quot;DialogBox&quot;, &quot;ExclDialogBox&quot;) rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;CopyFile&quot;, &quot;ExclCopyFile&quot;) rename(&quot;ReplaceText&quot;, &quot;ExclReplaceText&quot;)
</pre>
</li>
</ol>
<p>So in conclusion, in order to import the Excel 2007 Type Library in C++ and use it in your automations, 3 files must be imported, MSO.DLL, VBE6EXT.OLB, and EXCEL.EXE.  On top of those three files, various objects must be renamed due to already being defined.  In my case it was the DialogBox and RGB, though it may differ on each project depending on what is defined.  Here is the final code needed to import the type library.</p>
<pre class="brush: cpp; title: ; notranslate">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL&quot; no_implementation rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;DocumentProperties&quot;, &quot;ExclDocumentProperties&quot;) rename(&quot;SearchPath&quot;, &quot;ExclSearchPath&quot;)
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation
#import &quot;D:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE&quot; rename(&quot;DialogBox&quot;, &quot;ExclDialogBox&quot;) rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;CopyFile&quot;, &quot;ExclCopyFile&quot;) rename(&quot;ReplaceText&quot;, &quot;ExclReplaceText&quot;)
</pre>
<p>Useful Links:</p>
<ul>
<li><a href="http://groups.google.com/group/microsoft.public.vc.language/msg/d82ee4d7b85fbed1">Reading a cell from an Excel Worksheet</a></li>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/1de6c74f-6cf0-4d91-a5a9-e85853b867f6">Using Excel Type Library in VS 2005</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
