<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>in Chris Velazquez's words... - office</title>
    <link>http://www.chrisvelazquez.com/blog/</link>
    <description>a blog fertilized by my mental droppings</description>
    <language>en-us</language>
    <copyright>Christopher S. Velazquez</copyright>
    <lastBuildDate>Wed, 07 Feb 2007 17:27:09 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>chris@chrisvelazquez.com</managingEditor>
    <webMaster>chris@chrisvelazquez.com</webMaster>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=ed29e8d6-061f-48ed-b15c-58f3e3db33a4</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,ed29e8d6-061f-48ed-b15c-58f3e3db33a4.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,ed29e8d6-061f-48ed-b15c-58f3e3db33a4.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ed29e8d6-061f-48ed-b15c-58f3e3db33a4</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I can't believe that I've been racking my brains for hours trying to figure out how
to execute my .NET 2.0 code in Microsoft Excel 2003.  Hopefully this tidbit of
information will save somebody else on the web some pain, frustration and time.
</p>
        <p>
Punchline: You need a file called EXCEL.EXE.CONFIG in the same directory as EXCEL.EXE.
</p>
        <p>
I created a class, written in C# and compiled with Visual Studio .NET 2005, with the
.NET 2.0 Framework.  This class has a COM Interop wrapper so that it can consumed
by ActiveX clients, most notably Excel 2003.  This class was compiled with the
"Register for COM interop" setting in the properties turned on.  This arrangement
autogenerates the GUIDs and COM interface for you, though I prefer to define my own
COM interfaces manually in production code.
</p>
        <p>
Here is a sample class in C#:
</p>
        <p>
          <font face="Courier New">// COMClass.cs<br />
using System.Windows.Forms;</font>
        </p>
        <p>
          <font face="Courier New">namespace AnyCOMLib {<br />
    public class COMClass {<br />
        public void DoSomething() {<br />
            MessageBox.Show("I
did something.");<br />
        }<br />
    }<br />
}</font>
        </p>
        <p>
When I compiled this C# class, Visual Studio generated the DLL and TLB files I expected. 
You can invoke it from a COM client, and it seems to work.  Here is the VB code:
</p>
        <p>
          <font face="Courier New">Dim thing As Object<br />
Set thing = CreateObject("AnyCOMLib.COMClass")<br />
thing.DoSomething</font>
        </p>
        <p>
I typed out a simple VBScript file with this code, and it worked.  A message
box popped up saying "I did something.".
</p>
        <p>
          <img src="http://www.chrisvelazquez.com/blog/content/binary/.net-com-interop.gif" border="0" />
        </p>
        <p>
I created a simple VB 6.0 program with this code, and this worked, too.  The
same message box displayed.
</p>
        <p>
I created a VBA macro in Excel 2003.  This did <u>not</u> work.  I had a
message that read:
</p>
        <p>
Run-time error '-2147024894 (80070002)':<br />
File or assembly name AnyCOMLib, or one of its dependencies, was not found.
</p>
        <p>
          <img src="http://www.chrisvelazquez.com/blog/content/binary/2147024894.gif" border="0" />
        </p>
        <p>
So I thought - If I can create a VB6 DLL that can be called from Excel (true) and
VB6 code can call my COM-wrapped C# code (also true) then why not create a VB6 DLL
that calls my C# code and call <em>that</em> from Excel?  Unfortunately, Excel
was not easily fooled by this subversion, and I continued to get the -2147024894 error. 
That was a waste of time.
</p>
        <p>
After spinning my wheels for too long, I finally found something helpful.  It
turns out that I need a file named Excel.exe.config to be placed in the same directory
as Excel.exe (typically at C:\Program Files\Microsoft Office\Office11).  That
file has the following format:
</p>
        <p>
          <font face="Courier New">&lt;configuration&gt;<br />
    &lt;startup&gt;<br />
        &lt;supportedRuntime version="v2.0.50727"/&gt;<br />
        &lt;supportedRuntime version="v1.1.4322"/&gt;<br />
    &lt;/startup&gt;<br />
&lt;/configuration&gt;</font>
        </p>
        <p>
You have to make sure that you have the correct supportedRuntime elements for the
.NET runtime to work.
</p>
        <p>
Here are links to the pages that helped me find out about this:
</p>
        <p>
          <a href="http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_frm/thread/3c4286a1e2887e3b/a05c57869aa3d896?lnk=st&amp;q=supportedRuntime+%22v-phuang%22+winword.exe&amp;rnum=3&amp;hl=en#a05c57869aa3d896">newsgroup
microsoft.public.dotnet.framework.sdk</a>
        </p>
        <p>
          <a href="http://www.msnewsgroups.net/group/microsoft.public.dotnet.languages.csharp/topic15171.aspx">topic
in msnewgroups.net</a>
        </p>
        <p>
These were specifically targetted for MS Word, but the same method applies
to running .NET assemblies in Excel 2003 as well.
</p>
        <p>
I hope this helps somebody!
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=ed29e8d6-061f-48ed-b15c-58f3e3db33a4" />
      </body>
      <title>Running .NET Code from Microsoft Office 2003</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,ed29e8d6-061f-48ed-b15c-58f3e3db33a4.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,ed29e8d6-061f-48ed-b15c-58f3e3db33a4.aspx</link>
      <pubDate>Wed, 07 Feb 2007 17:27:09 GMT</pubDate>
      <description>&lt;p&gt;
I can't believe that I've been racking my brains for hours trying to figure out how
to execute my .NET 2.0 code in Microsoft Excel 2003.&amp;nbsp; Hopefully this tidbit of
information will save somebody else on the web some pain, frustration and time.
&lt;/p&gt;
&lt;p&gt;
Punchline: You need a file called EXCEL.EXE.CONFIG in the same directory as EXCEL.EXE.
&lt;/p&gt;
&lt;p&gt;
I created a class, written in C# and compiled with Visual Studio .NET 2005, with the
.NET 2.0 Framework.&amp;nbsp; This class has a COM Interop wrapper so that it can consumed
by ActiveX clients, most notably Excel 2003.&amp;nbsp; This class was compiled with the
"Register for COM interop" setting in the properties turned on.&amp;nbsp; This arrangement
autogenerates the GUIDs and COM interface for you, though I prefer to define my own
COM interfaces manually in production code.
&lt;/p&gt;
&lt;p&gt;
Here is a sample class in C#:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;// COMClass.cs&lt;br&gt;
using System.Windows.Forms;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;namespace AnyCOMLib {&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;public class COMClass {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void DoSomething() {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("I
did something.");&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
When I compiled this C# class, Visual Studio generated the DLL and TLB files I expected.&amp;nbsp;
You can invoke it from a COM client, and it seems to work.&amp;nbsp; Here is the VB code:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Dim thing As Object&lt;br&gt;
Set thing = CreateObject("AnyCOMLib.COMClass")&lt;br&gt;
thing.DoSomething&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
I typed out a simple VBScript file with this code, and it worked.&amp;nbsp; A message
box popped up saying "I did something.".
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.chrisvelazquez.com/blog/content/binary/.net-com-interop.gif" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
I created a simple VB 6.0 program with this code, and this worked, too.&amp;nbsp; The
same message box displayed.
&lt;/p&gt;
&lt;p&gt;
I created a VBA macro in Excel 2003.&amp;nbsp; This did &lt;u&gt;not&lt;/u&gt; work.&amp;nbsp; I had a
message that read:
&lt;/p&gt;
&lt;p&gt;
Run-time error '-2147024894 (80070002)':&lt;br&gt;
File or assembly name AnyCOMLib, or one of its dependencies, was not found.
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.chrisvelazquez.com/blog/content/binary/2147024894.gif" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
So I thought - If I can create a VB6 DLL that can be called from Excel (true) and
VB6 code can call my COM-wrapped C# code (also true) then why not create a VB6 DLL
that calls my C# code and call &lt;em&gt;that&lt;/em&gt; from Excel?&amp;nbsp; Unfortunately, Excel
was not easily fooled by this subversion, and I continued to get the -2147024894 error.&amp;nbsp;
That was a waste of time.
&lt;/p&gt;
&lt;p&gt;
After spinning my wheels for too long, I finally found something helpful.&amp;nbsp; It
turns out that I need a file named Excel.exe.config to be placed in the same directory
as Excel.exe (typically at C:\Program Files\Microsoft Office\Office11).&amp;nbsp; That
file has the following format:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;lt;configuration&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;startup&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;supportedRuntime version="v2.0.50727"/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;supportedRuntime version="v1.1.4322"/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/startup&amp;gt;&lt;br&gt;
&amp;lt;/configuration&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
You have to make sure that you have the correct supportedRuntime elements for the
.NET runtime to work.
&lt;/p&gt;
&lt;p&gt;
Here are links to the pages that helped me find out about this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_frm/thread/3c4286a1e2887e3b/a05c57869aa3d896?lnk=st&amp;amp;q=supportedRuntime+%22v-phuang%22+winword.exe&amp;amp;rnum=3&amp;amp;hl=en#a05c57869aa3d896"&gt;newsgroup
microsoft.public.dotnet.framework.sdk&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.msnewsgroups.net/group/microsoft.public.dotnet.languages.csharp/topic15171.aspx"&gt;topic
in msnewgroups.net&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
These were specifically&amp;nbsp;targetted&amp;nbsp;for MS Word, but the same method applies
to running .NET assemblies in Excel 2003 as well.
&lt;/p&gt;
&lt;p&gt;
I hope this helps somebody!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=ed29e8d6-061f-48ed-b15c-58f3e3db33a4" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,ed29e8d6-061f-48ed-b15c-58f3e3db33a4.aspx</comments>
      <category>.net;office</category>
    </item>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=1ade8044-e7b5-45f3-b1c5-9099b0e29257</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1ade8044-e7b5-45f3-b1c5-9099b0e29257</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have this habit of underestimating Microsoft, especially when it comes to the Office
product line. At first blush, I was unimpressed with Office 2007.  To the average
user, on first glance, it looks like Microsoft has traded one set of GUI widgets for
another set of more complicated GUI widgets.  Combining this with the IT pundits
declaring Office 2007 dead on arrival, I ignored it.  It's hard for me to get
very excited about new widgets.
</p>
        <p>
But last night I chanced upon the <a href="http://msdn2.microsoft.com/en-us/office/aa905543.aspx">VSTO
site</a> (Visual Studio Tools for Office), and took a peek at <a href="http://wm.microsoft.com/ms/msdn/office/vsto2005seintro/vsto2005seintro.wmv">this
video</a>.  I was amazed, and had to concede that Microsoft had pulled it
off once again.  They have raised the bar for us programmers and expectations
of users.  Briefly, your WinForms user controls can plug right into the Office
environment, into either the ribbon or in the side docking panel.  Having worked
on a system in C# that emulates a similar behavior, I was very interested,
and a little disappointed that my craftily written code would soon be obsolete.
</p>
        <p>
The thing about Office, and Word and Excel in particular, is that everyone uses it. 
People get a warm fuzzy from software they use frequently and have some understanding
of.  The number one feature request I get is to be able to download data into
an Excel spreadsheet.  And VSTO 2005 SE (Second Edition) makes the job for programmers
integrating into Office a whole lot better.  And it gives a compelling reason
to upgrade to Office 2007.  This is only a minor upgrade for the end-user, but
this is a sea-change upgrade for the Office developer.
</p>
        <p>
VSTO 2005 SE will also allow Office programmers to achieve the type of service-oriented
architecture that was difficult to achieve with our previous tools.  Since your
user controls can do all those wonderful things like consume web services, chat over
networks, query databases, access the file system, etc., the integration possibilities
are nearly endless.  And the ability to dock your components right at the user's
fingertips within the Office application makes the software convenient to summon for
the end-user.
</p>
        <p align="right">
          <img src="http://www.chrisvelazquez.com/blog/content/binary/aa905543_NewVSTOlogo(en-us,MSDN_10).jpg" border="0" />
        </p>
        <p>
Now to work on my "reasons to upgrade" spiel for my clients...
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=1ade8044-e7b5-45f3-b1c5-9099b0e29257" />
      </body>
      <title>Why Office 2007 Really Does Rock</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</link>
      <pubDate>Wed, 31 Jan 2007 17:13:09 GMT</pubDate>
      <description>&lt;p&gt;
I have this habit of underestimating Microsoft, especially when it comes to the Office
product line. At first blush, I was unimpressed with Office 2007.&amp;nbsp; To the average
user, on first glance, it looks like Microsoft has traded one set of GUI widgets for
another set of more complicated GUI widgets.&amp;nbsp; Combining this with the IT pundits
declaring Office 2007 dead on arrival, I ignored it.&amp;nbsp; It's hard for me to get
very excited about new widgets.
&lt;/p&gt;
&lt;p&gt;
But last night I chanced upon the &lt;a href="http://msdn2.microsoft.com/en-us/office/aa905543.aspx"&gt;VSTO
site&lt;/a&gt; (Visual Studio Tools for Office), and took a peek at &lt;a href="http://wm.microsoft.com/ms/msdn/office/vsto2005seintro/vsto2005seintro.wmv"&gt;this
video&lt;/a&gt;.&amp;nbsp; I was amazed, and had to concede that Microsoft had&amp;nbsp;pulled it
off once again.&amp;nbsp; They have raised the bar for us programmers and expectations
of users.&amp;nbsp; Briefly, your WinForms user controls can plug right into the Office
environment, into either the ribbon or in the side docking panel.&amp;nbsp; Having worked
on a system&amp;nbsp;in C#&amp;nbsp;that emulates a similar behavior, I was very interested,
and a little disappointed that my craftily written code would soon be obsolete.
&lt;/p&gt;
&lt;p&gt;
The thing about Office, and Word and Excel in particular, is that everyone uses it.&amp;nbsp;
People get a warm fuzzy from software they use frequently and have some understanding
of.&amp;nbsp; The number one feature request I get is to be able to download data into
an Excel spreadsheet.&amp;nbsp; And VSTO 2005 SE (Second Edition) makes the job for programmers
integrating into Office a whole lot better.&amp;nbsp; And it gives a compelling reason
to upgrade to Office 2007.&amp;nbsp; This is only a minor upgrade for the end-user, but
this is a sea-change upgrade for the Office developer.
&lt;/p&gt;
&lt;p&gt;
VSTO 2005 SE will also allow Office programmers to achieve the type of service-oriented
architecture that was difficult to achieve with our previous tools.&amp;nbsp; Since your
user controls can do all those wonderful things like consume web services, chat over
networks, query databases, access the file system, etc., the integration possibilities
are nearly endless.&amp;nbsp; And the ability to dock your components right at the user's
fingertips within the Office application makes the software convenient to summon for
the end-user.
&lt;/p&gt;
&lt;p align=right&gt;
&lt;img src="http://www.chrisvelazquez.com/blog/content/binary/aa905543_NewVSTOlogo(en-us,MSDN_10).jpg" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Now to work on my "reasons to upgrade" spiel for my clients...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=1ade8044-e7b5-45f3-b1c5-9099b0e29257" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</comments>
      <category>.net;database;office</category>
    </item>
  </channel>
</rss>