<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>.NET4Office : Office Programming Model</title><link>http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx</link><description>Tags: Office Programming Model</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Setting a Range of Cells in One Call</title><link>http://blogs.msdn.com/eric_carter/archive/2005/03/16/396886.aspx</link><pubDate>Wed, 16 Mar 2005 17:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:396886</guid><dc:creator>Eric Carter</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/396886.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=396886</wfw:commentRss><description>&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;A reader writes:&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;I've enjoyed reading your online blog about Excel/Dotnet integration. I have a question, that if anyone would know the answer to, hopefully you do. &lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;Is there any trick that can be used to speed up insertion of large blocks of data into a worksheet from dotnet? For example, I may have a large rectangular array I retrieved as the result of a database query that I set into the Value of a range.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Here’s how you do this.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You need to create an object array dimensioned to the size of the block you want to set.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Populate the object array.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You also need to get a Range object that spans the size of block.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Then you use the Value2 property and set it to your object array.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Here’s an example that does this:&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Sheet1_Startup(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; sender, System.&lt;span style="COLOR: navy"&gt;EventArgs&lt;/span&gt; e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; numberOfRows = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; numberOfColumns = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[,] theValues = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[numberOfRows, numberOfColumns];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numberOfRows; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; j = 0; j &amp;lt; numberOfColumns; j++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;theValues[i, j] = i * j;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Excel.&lt;span style="COLOR: navy"&gt;Range&lt;/span&gt; theRange = &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.Range[&lt;span style="COLOR: maroon"&gt;"A1"&lt;/span&gt;, &lt;span style="COLOR: maroon"&gt;"J10"&lt;/span&gt;];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;theRange.Value2 = theValues;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=396886" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>VSTO Security Model Principles</title><link>http://blogs.msdn.com/eric_carter/archive/2005/03/01/382673.aspx</link><pubDate>Tue, 01 Mar 2005 21:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:382673</guid><dc:creator>Eric Carter</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/382673.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=382673</wfw:commentRss><description>&lt;p&gt;VSTO takes a very strong stance on security to prevent the spread of macro viruses or worms.&amp;nbsp; VSTO's security model involves the trust of two things: 1) the assembly associated with the document must be trusted and 2) the location the document is coming from must be trusted.&amp;nbsp;&amp;nbsp; VSTO's default security model for assemblies is that no assembly is trusted by default.&amp;nbsp; VSTO's default security model for documents is that only documents on the local machine are trusted by default.&amp;nbsp; When a VSTO customized document is loaded both assembly trust and document location trust are checked to determine whether to load.&amp;nbsp; No matter where the assembly is, you must have .NET policy in place to trust the assembly.&amp;nbsp; If the customized document resides locally on your computer this is sufficient.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;But if the customized document is being opened from the intranet or internet zone (such as from &lt;a href="http://myserver/myvstodoc.xls"&gt;http://myserver/myvstodoc.xls&lt;/a&gt;) then you must add additional .NET policy to trust the location the document is coming from.&amp;nbsp; This is to prevent a repurposing attack where a document from an untrusted intranet or more likely internet zone tries to repurpose a VSTO document customization that the attacker knows is trusted within an organization.&amp;nbsp; It is also to protect from an attack where a repurposed document comes in through e-mail--any document opened directly from e-mail is in the internet zone and won't be trusted until you "save it to disk" e.g. copy it to your local computer.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;One solution is to the document location trust problem is to copy the document to your local machine which puts it in the "Local Machine" zone and VSTO will then trust the document location (since the document is now copied to Local Machine) and will load the customization if there is .NET policy to trust the associated assembly.&amp;nbsp; The other option is to add .NET security policy to trust customized documents coming &lt;a href="http://myserver"&gt;http://myserver&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I will provide more detail in a future post on how to configure .NET security policy to trust assemblies and how to configure .NET security policy to trust documents.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=382673" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Want to work on VSTO technologies?</title><link>http://blogs.msdn.com/eric_carter/archive/2005/02/21/377691.aspx</link><pubDate>Mon, 21 Feb 2005 23:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:377691</guid><dc:creator>Eric Carter</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/377691.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=377691</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Visual Studio Tools for Office is really taking off and the team that creates VSTO is growing fast.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;If you are interested in working at Microsoft and helping us build tools to help developers build customizations for Office, please check out this list of openings on the VSTO team: &lt;/font&gt;&lt;a href="http://ericca.members.winisp.net/VSTOJobs.html"&gt;&lt;u&gt;&lt;font color="#0000ff"&gt;&lt;font face="Verdana" size="2"&gt;http://ericca.members.winisp.net/VSTOJobs.html&lt;/font&gt;&lt;/u&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt;.&amp;nbsp; There are test, developer, and program management positions that are open.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;You can use the "Contact" link at the left to submit resume and contact information directly to me and I'll work to hook you up with the right people providing your background and experience look like they hit the mark.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=377691" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Awesome Videos Illustrating VSTO's Data Binding Features</title><link>http://blogs.msdn.com/eric_carter/archive/2005/01/19/356256.aspx</link><pubDate>Wed, 19 Jan 2005 19:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:356256</guid><dc:creator>Eric Carter</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/356256.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=356256</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Kathleen has just posted two new videos showing how VSTO's Data Binding Features work.&amp;nbsp; I guarantee you'll be wowed by these videos.&amp;nbsp; The first shows the creation of a databound list and controls in Excel created by simply dragging and dropping.&amp;nbsp; The second shows how to create databound bookmarks in a Word document.&amp;nbsp; They are each only about 5 minutes long.&amp;nbsp; Check 'em out.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a title="http" href="http://vsto.members.winisp.net/videos/Demo%209%20--%20How%20to%20Bind%20Data%20to%20Controls%20in%20Excel.wmv"&gt;&lt;font title="http" face="Verdana" size="2"&gt;Demo 9 -- How to Bind Data to Controls&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt;&amp;nbsp;&lt;br /&gt; &lt;/font&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%2010%20--%20How%20to%20Bind%20Data%20to%20Controls%20in%20Word.wmv"&gt;&lt;font face="Verdana" size="2"&gt;Demo 10 -- How to Bind Data to Controls on a Word Document&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt;.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=356256" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Some new VSTO resources</title><link>http://blogs.msdn.com/eric_carter/archive/2005/01/08/349208.aspx</link><pubDate>Sat, 08 Jan 2005 18:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:349208</guid><dc:creator>Eric Carter</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/349208.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=349208</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;If you haven't checked it out yet, Chris Kunicki has created a VSTO Zone at his site that has a bunch of useful information about VSTO:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;a href="http://www.officezealot.com/vsto/" target="_new"&gt;&lt;u&gt;&lt;font face="Verdana" size="2"&gt;http://www.officezealot.com/vsto/&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;font face="Verdana" size="2"&gt;Also, Kathleen has posted some more VSTO video tutorials:&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%205%20--%20How%20to%20Resize%20Excel%20Controls.wmv"&gt;&lt;font face="Verdana" size="2"&gt;Demo 5--How to Resize Excel Controls&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;D&lt;/font&gt;&lt;/a&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;e&lt;/font&gt;&lt;/a&gt;&lt;span class="471512806"&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;mo 6 - How to Add Controls to the Actions Pane&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%207--How%20to%20Set%20the%20Stack%20Order%20of%20Controls%20on%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;Demo 7 – How to Set the Stack Order of Controls on the Actions Pane&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://vsto.members.winisp.net/videos/Demo%208%20--%20How%20to%20Change%20Controls%20on%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;Demo 8 - How to Change Controls on the Actions Pane&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=349208" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Working with Word Collections and using get_Item</title><link>http://blogs.msdn.com/eric_carter/archive/2004/12/29/343976.aspx</link><pubDate>Wed, 29 Dec 2004 22:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:343976</guid><dc:creator>Eric Carter</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/343976.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=343976</wfw:commentRss><description>&lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;Items in a Word collection are accessed in two different ways depending on whether the index into the collection is strongly typed or weakly typed.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In the case of the KeyBindings collection for example, the index is strongly typed as an integer.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;As such, you can use the index operation ([]) to get to an item in a collection.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The code looks like this:&lt;/font&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Word.KeyBinding k = Application.KeyBindings[1];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;For a collection for which the index into the collection is weakly typed as an &lt;span class="C1"&gt;&lt;span style="FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'"&gt;object&lt;/span&gt;&lt;/span&gt; passed by reference, you must use the &lt;b style="mso-bidi-font-weight: normal"&gt;get_Item&lt;/b&gt; method of the collection.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The Templates collection is an example of this.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It has a weakly typed index of type &lt;span class="C1"&gt;&lt;span style="FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'"&gt;object&lt;/span&gt;&lt;/span&gt; passed by reference.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This is because you can either pass a string if you know the name of the template in the collection or you can pass an integer for the index of the template in the collection.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To get a Template from the Templates collection by integer index you can write this code:&lt;/font&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;object index = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Word.Template t = Application.Templates.get_Item(ref index);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;To get a Template from the Templates collection by string name you can write this code:&lt;/font&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;object index = "Normal.dot";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Word.Template t = Application.Templates.get_Item(ref index);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;Note that in both cases, you must declare an object first and then pass a reference to the object. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;When passing parameters by reference, you must always declare a variable first and then pass that declared variable by reference.&lt;/font&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana"&gt;&lt;font size="2"&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:mswterms w:st="on"&gt;Visual Studio&lt;/st1:mswterms&gt; isn’t much help when trying to figure this out.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It will encourage you to use the index operator even on a collection like templates through Intellisense prompts as shown below.&amp;nbsp; But if you try to use the index operator when the index is passed by reference, you will get a compile error.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://ericca.members.winisp.net/images/badintellisense1.jpg" /&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;&lt;v:shapetype id=_x0000_t75 path="m@4@5l@4@11@9@11@9@5xe" stroked="f" filled="f" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:formulas&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;&lt;/v:formulas&gt;&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;&lt;o:lock aspectratio="t" v:ext="edit"&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;font face="Verdana" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;em&gt;&lt;font face="Verdana"&gt;&lt;font size="2"&gt;&lt;st1:mswterms w:st="on"&gt;Visual Studio&lt;/st1:mswterms&gt; Intellisense leads you down the wrong path of using the index operator with an object parameter passed by reference.&lt;/font&gt;&lt;/font&gt; &lt;/em&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;Furthermore, &lt;st1:mswterms w:st="on"&gt;Visual Studio&lt;/st1:mswterms&gt; Intellisense doesn’t display get_Item as a method you can call on the collection in the popup Intellisense as shown below.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Nonetheless, get_Item is an available method on Word collections.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://ericca.members.winisp.net/images/badintellisense2.jpg" /&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&lt;em&gt;&lt;font face="Verdana" size="2"&gt;Visual Studio Intellisense Doesn't Show the get_Item method.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p class="Body" style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=343976" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Writing user defined functions for Excel in .NET</title><link>http://blogs.msdn.com/eric_carter/archive/2004/12/01/writing-user-defined-functions-for-excel-in-net.aspx</link><pubDate>Wed, 01 Dec 2004 20:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:273127</guid><dc:creator>Eric Carter</dc:creator><slash:comments>16</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/273127.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=273127</wfw:commentRss><description>&lt;DIV class=Section1&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;I've updated this article with some new guidance--&lt;A class="" href="http://blogs.msdn.com/eric_carter/archive/2008/04/03/updated-instructions-for-writing-user-defined-functions-for-excel-in-net.aspx" mce_href="http://blogs.msdn.com/eric_carter/archive/2008/04/03/updated-instructions-for-writing-user-defined-functions-for-excel-in-net.aspx"&gt;for the details, see this post&lt;/A&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Excel enables the creation of user defined functions that can be used in Excel formulas.&amp;nbsp; A developer must create a special kind of DLL called an XLL.&amp;nbsp; Excel also allows you to write custom functions in VBA that can be used in Excel formulas.&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Unfortunately, Excel does not support or recommend writing an XLL that uses managed code.&amp;nbsp; If you are willing to take your chances that your XLL might not run in current or future versions of Excel, there are solutions available that enable this scenario—search the web for “managed XLL”.&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Fortunately, there is an easier way to create a user defined function that doesn’t require you to create an XLL dll.&amp;nbsp; Excel XP, Excel 2003, and Excel 2007&amp;nbsp;support something called an Automation Add-in.&amp;nbsp; An Automation Add-in can be created quite simply in C# or VB.NET.&amp;nbsp; I'm going to show you an example in C#.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;First, launch Visual Studio 2005 or Visual Studio&amp;nbsp;2008&amp;nbsp;and create a new C# class library project called AutomationAddin for this example.&amp;nbsp; Screenshots here will show Visual Studio 2005 and Excel 2003, but the steps are pretty much the same for Visual Studio 2008 and Excel 2007.&amp;nbsp; I'll note inline where they are different.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas1.jpg" mce_src="http://ericca.members.winisp.net/images/formulas1.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Then, in your Class1.cs file, enter the code shown below.&amp;nbsp; Replace the GUID with your own GUID that you create by using Generate GUID in the Tools menu of Visual Studio.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System;&lt;BR&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/SPAN&gt;&lt;/FONT&gt; System.Runtime.InteropServices;&lt;BR&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/SPAN&gt;&lt;/FONT&gt; Microsoft.Win32;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;namespace&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; AutomationAddin&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;// Replace the Guid below with your own guid that&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;// you generate using Create GUID from the Tools menu&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"5268ABE2-9B09-439d-BE97-2EA60E103EF6"&lt;/SPAN&gt;)]&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; [&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;ClassInterface&lt;/SPAN&gt;&lt;/FONT&gt;(&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;ClassInterfaceType&lt;/SPAN&gt;&lt;/FONT&gt;.AutoDual)]&lt;BR&gt;&amp;nbsp; [ComVisible(true)]&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=teal size=2&gt;&lt;SPAN style="COLOR: teal"&gt;MyFunctions&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;MyFunctions&lt;/SPAN&gt;&lt;/FONT&gt;()&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New" color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; MultiplyNTimes(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; number1, &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; number2, &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; timesToMultiply)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; result = number1;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;&lt;/FONT&gt; (&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; i = 0; i &amp;lt; timesToMultiply; i++)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = result * number2;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; result;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;ComRegisterFunctionAttribute&lt;/SPAN&gt;&lt;/FONT&gt;]&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt;&lt;/FONT&gt; RegisterFunction(&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Type&lt;/SPAN&gt;&lt;/FONT&gt; type)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Registry.ClassesRoot.CreateSubKey(&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;GetSubKeyName(type, "Programmable"));&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;RegistryKey key = Registry.ClassesRoot.OpenSubKey(&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;GetSubKeyName(type, "InprocServer32"), true);&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key.SetValue("",&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;System.Environment.SystemDirectory + @"\mscoree.dll",&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;RegistryValueKind.String);&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;ComUnregisterFunctionAttribute&lt;/SPAN&gt;&lt;/FONT&gt;]&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt;&lt;/FONT&gt; UnregisterFunction(&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Type&lt;/SPAN&gt;&lt;/FONT&gt; type)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Registry.ClassesRoot.DeleteSubKey(&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;GetSubKeyName(type, "Programmable"), false);&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;private static string GetSubKeyName(Type type, &lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;string subKeyName)&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;System.Text.StringBuilder s =&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;new System.Text.StringBuilder();&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s.Append(@"CLSID\{");&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s.Append(type.GUID.ToString().ToUpper());&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s.Append(@"}\");&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s.Append(subKeyName);&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return s.ToString();&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=LC2 style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; }&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;With this code written, show the properties for the project by double clicking on the properties node under the project in Solution Explorer.&amp;nbsp; Click on the Build tab and check the check box that says “Register for COM Interop”.&amp;nbsp; At this point you have an extra step if you are running on Windows Vista or higher.&amp;nbsp; Visual Studio has to be run with administrator privileges to register for COM interop.&amp;nbsp; Save your project and exit Visual Studio.&amp;nbsp; Then find Visual Studio in the Start menu and right click on it and choose "Run as Administrator".&amp;nbsp; Reopen your project in Visual Studio.&amp;nbsp; Then choose “Build” to build the add-in.&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Now launch Excel and go to the Tools, Add-ins dialog in Excel 2003&amp;nbsp;and click on the Automation button.&amp;nbsp; If you are running Excel 2007, you get to the Automation servers dialog by following these steps:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Launch Excel and click the Microsoft Office button in the top left corner of the window.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Choose Excel Options.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Click the Add-Ins tab in the Excel Options dialog.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;4.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Choose Excel Add-Ins from the combo box labeled Manage.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Then click the Go button.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;5.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Click the Automation button in the Add-Ins dialog.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;You can find the class you created by looking for AutomationAddin.MyFunctions in the list of Automation add-ins:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas2.jpg" mce_src="http://ericca.members.winisp.net/images/formulas2.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;By clicking OK in this dialog, you add AutomationAddin.MyFunctions to the list of installed add-ins as shown here.&amp;nbsp; In prior versions of these instructions, you would get a dialog at this point about not being able to find&amp;nbsp;mscoree.dll.&amp;nbsp; I've updated this article so this doesn't happen anymore--the magic is in the two final lines of RegisterFunction that register the full path to mscoree.dll which makes Excel happier.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas3.jpg" mce_src="http://ericca.members.winisp.net/images/formulas3.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Now, let’s try to use the function MultiplyNTimes inside Excel.&amp;nbsp; First create a simple spreadsheet that has a number, a second number to multiple the first by, and a third number for how many times you want to multiply the first number by the second number.&amp;nbsp; An example spreadsheet is shown here:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas4.jpg" mce_src="http://ericca.members.winisp.net/images/formulas4.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Click on an empty cell in the workbook below the numbers and then click on the Insert Function button in the formula bar.&amp;nbsp; From the dialog of available formulas, drop down the “Or select a category” drop down box and choose “AutomationAddin.MyFunctions.&amp;nbsp; Then click on the MultiplyNTimes function as shown here:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas5.jpg" mce_src="http://ericca.members.winisp.net/images/formulas5.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;When you press the OK button, Excel pops up a dialog to help you grab function arguments from the spreadsheet as shown here:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas6.jpg" mce_src="http://ericca.members.winisp.net/images/formulas6.jpg"&gt; 
&lt;P class=Body&gt;&lt;FONT face=Verdana color=black size=2&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;Finally, click OK and see your final spreadsheet as shown here with your custom formula in cell C5.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://ericca.members.winisp.net/images/formulas7.jpg" mce_src="http://ericca.members.winisp.net/images/formulas7.jpg"&gt; 
&lt;P class=Body style="TEXT-INDENT: 0in"&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=3&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;You might experiment with other functions that return other types of values.&amp;nbsp; For example, the code snippet below shows several other functions you could add to your MyFunctions class.&amp;nbsp; To use this code you must add a reference to the Excel 11.0 Object Library for Excel 2003 or the Excel 12.0 Object model for Excel 2007 and also add the code “&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN class=C1&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;using Excel = Microsoft.Office.Interop.Excel&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;” to the top of your class file.&amp;nbsp; Note in particular that when you declare a parameter as an object, Excel passes you a Range object.&amp;nbsp; Also note how optional parameters are supported by AddNumbers.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;/FONT&gt; GetStars(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; Number)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;/FONT&gt; s = &lt;FONT color=maroon&gt;&lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;&lt;/FONT&gt; (&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; i = 0; i &amp;lt; Number; i++)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = s + &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=maroon&gt;&lt;SPAN style="COLOR: maroon"&gt;"*"&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; }&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; s;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; AddNumbers(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; Number1, [&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Optional&lt;/SPAN&gt;&lt;/FONT&gt;] &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;/FONT&gt; Number2, [&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Optional&lt;/SPAN&gt;&lt;/FONT&gt;] &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;/FONT&gt; Number3)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; result = 0;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; result += &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Convert&lt;/SPAN&gt;&lt;/FONT&gt;.ToDouble(Number1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;&lt;/FONT&gt; (!(Number2 &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;is&lt;/SPAN&gt;&lt;/FONT&gt; System.Reflection.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Missing&lt;/SPAN&gt;&lt;/FONT&gt;))&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Excel.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt; r2 = Number2 &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt;&lt;/FONT&gt; Excel.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d2 = &lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Convert&lt;/SPAN&gt;&lt;/FONT&gt;.ToDouble(r2.Value2);&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result += d2;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;&lt;/FONT&gt; (!(Number3 &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;is&lt;/SPAN&gt;&lt;/FONT&gt; System.Reflection.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Missing&lt;/SPAN&gt;&lt;/FONT&gt;))&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Excel.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt; r3 = Number3 &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt;&lt;/FONT&gt; Excel.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d3 = &lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Convert&lt;/SPAN&gt;&lt;/FONT&gt;.ToDouble(r3.Value2);&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result += d3;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; result;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; CalculateArea(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;/FONT&gt; Range)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; Excel.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt; r = Range &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt;&lt;/FONT&gt; Excel.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; &lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Convert&lt;/SPAN&gt;&lt;/FONT&gt;.ToDouble(r.Width)&amp;nbsp;* &lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Convert&lt;/SPAN&gt;&lt;/FONT&gt;.ToDouble(r.Height);&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; NumberOfCells(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;/FONT&gt; Range)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; Excel.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt; r = Range &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt;&lt;/FONT&gt; Excel.&lt;FONT color=teal&gt;&lt;SPAN style="COLOR: teal"&gt;Range&lt;/SPAN&gt;&lt;/FONT&gt;;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; r.Cells.Count;&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=LC2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=blue&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;/FONT&gt; ToUpperCase(&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;/FONT&gt; input)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;/FONT&gt; input.ToUpper();&lt;BR&gt;&lt;FONT color=black&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=273127" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>When foreach in Excel goes wrong</title><link>http://blogs.msdn.com/eric_carter/archive/2004/11/18/265787.aspx</link><pubDate>Thu, 18 Nov 2004 18:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:265787</guid><dc:creator>Eric Carter</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/265787.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=265787</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;This seems like a reasonable piece of code:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;For Each oCell As Excel.Range In Me.Range("a1:b5")&lt;br /&gt;&amp;nbsp; oCell.Value = "test"&lt;br /&gt;Next&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;so does this:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;foreach Excel.CustomProperty prop in worksheet.CustomProperties&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; Console.WriteLine(prop.Name);&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font face="Courier New" size="2"&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Unfortunately, when you run this code you will get a "Missing member" exception.&amp;nbsp; Some collections in Excel can't be "for-eached" over.&amp;nbsp; To do "foreach" the CLR has to get an enumerator from the collection.&amp;nbsp; The CLR and CLR interop&amp;nbsp;expect to find a _NewEnum member &lt;strong&gt;method &lt;/strong&gt;on the collection.&amp;nbsp; Some Excel collections have a _NewEnum member that is&amp;nbsp;implemented as a&amp;nbsp;&lt;strong&gt;property &lt;/strong&gt;and not a method.&amp;nbsp; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;There is a KB on this issue:&amp;nbsp; &lt;a href="http://support.microsoft.com/?kbid=328347"&gt;http://support.microsoft.com/?kbid=328347&lt;/a&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;Clearly this is not happy, but there is a work around--use a for next loop&amp;nbsp;and get members of the collection using Item with a 1-based index.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;Hopefully, this is an issue we will get fixed in&amp;nbsp;VS 2005 so that all Excel collections, even the ones that have a _NewEnum member that is a property, can be for-eached.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=265787" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>More VSTO 2005 Video Magic</title><link>http://blogs.msdn.com/eric_carter/archive/2004/11/11/255852.aspx</link><pubDate>Thu, 11 Nov 2004 19:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:255852</guid><dc:creator>Eric Carter</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/255852.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=255852</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Kathleen has created two new videos you should check out.&amp;nbsp; Nice!&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="160031616"&gt;&lt;a title="http" href="http://www.winisp.net/vsto/video/Demo%205%20--%20How%20to%20Resize%20Excel%20Controls.wmv"&gt;&lt;font face="Verdana" size="2"&gt;Demo 5--How to Resize Excel Controls&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="160031616"&gt;&lt;a title="http" href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;D&lt;/font&gt;&lt;/a&gt;&lt;a title="http" href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;e&lt;/font&gt;&lt;/a&gt;&lt;span class="471512806"&gt;&lt;a title="http" href="http://vsto.members.winisp.net/videos/Demo%206%20--%20How%20to%20Add%20Controls%20to%20the%20Actions%20Pane.wmv"&gt;&lt;font face="Verdana" size="2"&gt;mo 6 - How to Add Controls to the Actions Pane&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=255852" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Office Watsoning and Exceptions in VSTO 2005 Beta 1</title><link>http://blogs.msdn.com/eric_carter/archive/2004/11/08/254221.aspx</link><pubDate>Tue, 09 Nov 2004 02:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:254221</guid><dc:creator>Eric Carter</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/254221.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=254221</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;[EDITOR'S NOTE] Blogging has been slow as we are spending almost all our time getting Beta 2 out the door.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;You may have had the experience of Excel or Word causing an Office Watson error at debug time when you have an exception that occurs in your Windows Forms event handlers in VSTO 2005.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;The problem is related to the way that Windows Forms is integrated into Excel and Word.&amp;nbsp; A Windows Forms windows procedure integrates with the existing Excel and Word message loops.&amp;nbsp; When the debugger is attached, Windows Forms uses a windows procedure that doesn't catch any exceptions that occur so that you can see those exceptions in the debugger.&amp;nbsp; When an exception occurs and you let it continue, the exception goes to the windows procedure and then propagates out to the Excel and Word message loops that are written in native code.&amp;nbsp; The Excel or Word message loop sees an exception that it doesn't know how to handle and invokes Office Watson and shuts down the process.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Theoretically, this should also repro in managed add-in development in other applications like Outlook--for example, if you create a modeless form and throw an exception from a handler within the modeless form.&amp;nbsp; I haven't gone and tried this though.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;This doesn't occur when you have an exception in a COM event handler like say the BeforeDoubleClick event for a NamedRange.&amp;nbsp; This is because the interop layer catches these exceptions and converts them to HRESULTs that Office ignores when firing events.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;This also doesn't occur for Windows Forms event handlers when the debugger is not attached because Windows Forms uses a different windows procedure that catches exceptions that occur and displays a dialog box.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;For VSTO 2005 Beta 2, we are working to change this behavior so Office won't Watson in any of these cases.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Also in Beta 1, you really should run with "Break when thrown" checked for Common Language Runtime Exceptions in your Exceptions dialog (Debug-&amp;gt;Exceptions-&amp;gt;Break On Specific Exceptions".&amp;nbsp; Otherwise, you will miss exceptions that are occurring in your code because they'll often get caught by the interop layer.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=254221" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Another officewiki.org plug.</title><link>http://blogs.msdn.com/eric_carter/archive/2004/10/27/248877.aspx</link><pubDate>Thu, 28 Oct 2004 03:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:248877</guid><dc:creator>Eric Carter</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/248877.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=248877</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;I've been doing some C# development with the Excel object model and when you look at Excel objects in the object browser or in intellisense there are two major problems you run into:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;1) Methods that would be hidden in VBA are shown in the object browser when using C#.&amp;nbsp; You really probably shouldn't be calling these hidden methods.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;2) It is hard to tell which parameters are required and which are optional.&amp;nbsp; I mean, you can usually guess that if it the parameter is of type object, it is probably optional and you can pass a Type.Missing to it, but you can't know for sure.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Which is why I've been using &lt;a href="http://www.officewiki.org"&gt;officewiki.org &lt;/a&gt;as a tool to help me with these problems.&amp;nbsp; Officewiki.org only shows you the methods and properties that are not hidden.&amp;nbsp; It also tells you explicitly which parameters are optional.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;It's really easy to type in a URL to get right to the object you want.&amp;nbsp; Here are some examples:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Workbooks object: &lt;/font&gt;&lt;a href="http://www.officewiki.org/default.aspx/Excel.Workbooks"&gt;&lt;font face="Verdana" size="2"&gt;http://www.officewiki.org/default.aspx/Excel.Workbooks&lt;/font&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Workbooks.Count property: &lt;/font&gt;&lt;a href="http://www.officewiki.org/default.aspx/Excel.WorkbooksCountProperty"&gt;&lt;font face="Verdana" size="2"&gt;http://www.officewiki.org/default.aspx/Excel.WorkbooksCountProperty&lt;/font&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Workbooks.Add method: &lt;/font&gt;&lt;a href="http://www.officewiki.org/default.aspx/Excel.WorkbooksAddMethod"&gt;&lt;font face="Verdana" size="2"&gt;http://www.officewiki.org/default.aspx/Excel.WorkbooksAddMethod&lt;/font&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Outlook Inspector object: &lt;/font&gt;&lt;a href="http://www.officewiki.org/default.aspx/Outlook.Inspector"&gt;&lt;font face="Verdana" size="2"&gt;http://www.officewiki.org/default.aspx/Outlook.Inspector&lt;/font&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;and so forth.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=248877" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>FAQ: Why do my forms in my managed add-in or VSTO 2003 look Windows 95-ish</title><link>http://blogs.msdn.com/eric_carter/archive/2004/10/22/246579.aspx</link><pubDate>Sat, 23 Oct 2004 04:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246579</guid><dc:creator>Eric Carter</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/246579.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=246579</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;This is a frequent question that comes up. You develop a managed add-in or VSTO 2003 code behind.&amp;nbsp; You show a windows form and yuck--it looks like Windows XP never happened.&amp;nbsp;The buttons aren't pretty like the Windows XP buttons.&amp;nbsp; Everything looks circa Windows 95.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;The trick is you have to tell Windows Forms to use the Windows XP theming by writing this line of code somewhere in your application before you start creating and showing forms:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;System.Windows.Forms.Application.EnableVisualStyles();&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;That's it!&amp;nbsp; Prettiness restored.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=246579" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>VSTO 2005 Video Magic</title><link>http://blogs.msdn.com/eric_carter/archive/2004/10/21/246052.aspx</link><pubDate>Fri, 22 Oct 2004 00:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246052</guid><dc:creator>Eric Carter</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/246052.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=246052</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;If you haven't had a chance yet to see these great videos that Kathleen has made of VSTO in action, check them out.&amp;nbsp; They're each about 6 minutes long are are really nice glimpses into some of the cool features of VSTO 2005.&amp;nbsp; Keep 'em coming Kathleen!&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&lt;span class="MsoHyperlink"&gt;&lt;a title="http" href="http://www.winisp.net/vsto/video/Demo%201%20--%20Locate%20and%20Delete%20NamedRange%20Controls.wmv"&gt;Demo 1 – Locate and Delete NamedRange Controls&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&lt;span class="MsoHyperlink"&gt;&lt;a title="http" href="http://www.winisp.net/vsto/video/Demo%202%20--%20Resize%20Controls%20Within%20Worksheet%20Cells.wmv"&gt;Demo 2 - Resize Controls Within Worksheet Cells&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&lt;span class="MsoHyperlink"&gt;&lt;a title="http" href="http://www.winisp.net/vsto/video/Demo%203%20--%20Add%20a%20Custom%20User%20Control%20to%20your%20Document.wmv"&gt;Demo 3 - Add a Custom User Control to your Document&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&lt;span class="MsoHyperlink"&gt;&lt;a title="http" href="http://www.winisp.net/vsto/video/Demo%204--How%20Column%20and%20Row%20Order%20is%20Persisted%20in%20a%20%20Data-Bound%20ListObject.wmv"&gt;Demo 4 - How Column and Row Order is Persisted in a Data-bound List Object&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=246052" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>More on getting Outlook to shut down</title><link>http://blogs.msdn.com/eric_carter/archive/2004/10/20/245386.aspx</link><pubDate>Wed, 20 Oct 2004 22:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245386</guid><dc:creator>Eric Carter</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/245386.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=245386</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;I recently posted some code showing how to get Outlook to shut down.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;I contended that you shouldn't have to call ReleaseCOMObject as is shown in some &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.asp"&gt;MSDN articles &lt;/a&gt;&lt;/font&gt;&lt;font face="Verdana" size="2"&gt;to get Outlook to shut down.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Indeed, David Mortenson who has worked on interop here at Microsoft &lt;/font&gt;&lt;A href="http://blogs.msdn.com/yvesdolc/archive/2004/04/17/115379.aspx"&gt;&lt;font face="Verdana" size="2"&gt;warns further about ReleaseCOMObject&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt;. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;One other point that David has made relating to the technique I showed for getting Outlook to shutdown (set variables containing Outlook OM objects to null and force a garbage collection and ) is that you actually sometimes have to write this code.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;//&amp;nbsp;Set objects using Outlook OM objects to null&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;GC.Collect();&lt;br /&gt;GC.WaitForPendingFinalizers();&lt;br /&gt;GC.Collect();&lt;br /&gt;GC.WaitForPendingFinalizers();&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;For my simple example where the objects I was setting to null were just variables pointing to Outlook OM objects, you wouldn't have to do this, but if you are setting a class to null which has a finalizer and that class has a variable containing an Outlook OM object, you would have to do this to make sure that class releases all it's OM objects it is holding on to.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245386" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item><item><title>Building a Status Report Application With VSTO 2005 &amp; Word</title><link>http://blogs.msdn.com/eric_carter/archive/2004/10/14/242412.aspx</link><pubDate>Thu, 14 Oct 2004 19:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:242412</guid><dc:creator>Eric Carter</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/eric_carter/comments/242412.aspx</comments><wfw:commentRss>http://blogs.msdn.com/eric_carter/commentrss.aspx?PostID=242412</wfw:commentRss><description>&lt;p&gt;&lt;font face="Arial" size="2"&gt;Another &lt;a href="http://msdn.microsoft.com/office/default.aspx?pull=/library/en-us/odc_vsto2005_ta/html/OfficeVSTOWordStatusReport.asp"&gt;new article on MSDN about VSTO 2005&lt;/a&gt;--this time by J. Jason De Lorme.&amp;nbsp; Jason mentions that VSTO 2005 doesn't support complex databinding against XMLNodes.&amp;nbsp; We did add an "UpdateXML" method (renamed to LoadXML in Beta 2) on an XMLNode that should make some of the tasks you do with XML in Word easier--I wonder if this would have helped Jason at all for his scenario.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=242412" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/eric_carter/archive/tags/Office+Programming+Model/default.aspx">Office Programming Model</category></item></channel></rss>