<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Visual Studio Office Developer (VSOD) Support Team</title><subtitle type="html" /><id>http://blogs.msdn.com/vsod/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/vsod/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-03-16T14:07:00Z</updated><entry><title>How to loop through the app-domains in the current process</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/11/30/how-to-loop-through-the-app-domains-in-the-current-process.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/11/30/how-to-loop-through-the-app-domains-in-the-current-process.aspx</id><published>2009-11-30T20:38:53Z</published><updated>2009-11-30T20:38:53Z</updated><content type="html">&lt;p&gt;Consider a scenario where we have a VSTO add-in and an automation add-in for Excel and we want to share some objects from the VSTO addin to the Automation add-in. Because the VSTO add-in is loaded in its own separate appdomain and the automation add-in is loaded in the different(default) appdomain, sharing objects is not that easy. One way to share objects could be to use &amp;quot;RequestCOMAutomationService&amp;quot; method as described in the following blog article:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/andreww/archive/2008/08/11/why-your-comaddin-object-should-derive-from-standardolemarshalobject.aspx"&gt;http://blogs.msdn.com/andreww/archive/2008/08/11/why-your-comaddin-object-should-derive-from-standardolemarshalobject.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;However, by using the above mentioned method, the object would be shared &amp;quot;ByVal&amp;quot;. What if we want to share the objects &amp;quot;ByRef&amp;quot;&lt;/p&gt;  &lt;p&gt;One of the solution to share objects &amp;quot;ByRef&amp;quot; is to use appdomain's &amp;quot;CreateInstanceAndUnwrap&amp;quot; method to create objects and to get the proxy objects. However to use &amp;quot;CreateInstanceAndUnwrap&amp;quot; method we need reference to the appdomain in which the actual objects will be created.&lt;/p&gt;  &lt;p&gt;In our scenario we need to have reference to the VSTO appdomain so that we can create objects in it and can obtain proxy objects in the automation appdomain.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Since VSTO appdomain is automatically created by VSTO runtime, we do not have reference to it. We need a way to loop through the appdomain present in the current process (Excel) and get a reference to the VSTO appdomain.&lt;/p&gt;  &lt;p&gt;To find the VSTO Appdomain (in a collection of appdomains), we will use its name. To find the VSTO appdomain's name, in the VSTO add-in code, we can use following code:&lt;/p&gt;  &lt;p&gt;AppDomain ad = System.Threading.Thread.GetDomain();    &lt;br /&gt;String VSTO_AppDomain_Name = ad.FriendlyName.ToString();&lt;/p&gt;  &lt;p&gt;This VSTO appdomain name can be shared with the Automation add-in using the RequestCOMAutomationService technique mentioned above or by using any other way.&lt;/p&gt;  &lt;p&gt;Although there is no managed API which enables us to loop through the appdomains, there is a way to loop through the app-domains in a process. The following code can be used to loop through the appdomains and to get reference to the VSTO appdomain:&lt;/p&gt;  &lt;pre class="csharpcode_ajay1"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Runtime.InteropServices; 
&lt;span class="kwrd"&gt;using&lt;/span&gt; mscoree; 
AppDomain VSTOAppDomain = &lt;span class="kwrd"&gt;null&lt;/span&gt;; 

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FindVSTOAppDomain(&lt;span class="kwrd"&gt;string&lt;/span&gt; VSTOAppDomainName) 
{ 
    IntPtr enumHandle = IntPtr.Zero; 
    CorRuntimeHostClass host = &lt;span class="kwrd"&gt;new&lt;/span&gt; mscoree.CorRuntimeHostClass(); 
    &lt;span class="kwrd"&gt;try&lt;/span&gt; 
    { 
        host.EnumDomains(&lt;span class="kwrd"&gt;out&lt;/span&gt; enumHandle); 
        &lt;span class="kwrd"&gt;object&lt;/span&gt; domain = &lt;span class="kwrd"&gt;null&lt;/span&gt;; 
        &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;) 
        { 
            host.NextDomain(enumHandle, &lt;span class="kwrd"&gt;out&lt;/span&gt; domain); 
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (domain == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;break&lt;/span&gt;; 
            AppDomain ad = (AppDomain)domain; 
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (ad.FriendlyName.Equals(VSTOAppDomainName)) 
            { 
                VSTOAppDomain = ad; 
            } 
        } 
    } 
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex) 
    { 

    } 
}&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode_ajay1, .csharpcode_ajay1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode_ajay1 pre { margin: 0em; }
.csharpcode_ajay1 .rem { color: #008000; }
.csharpcode_ajay1 .kwrd { color: #0000ff; }
.csharpcode_ajay1 .str { color: #006080; }
.csharpcode_ajay1 .op { color: #0000c0; }
.csharpcode_ajay1 .preproc { color: #cc6633; }
.csharpcode_ajay1 .asp { background-color: #ffff00; }
.csharpcode_ajay1 .html { color: #800000; }
.csharpcode_ajay1 .attr { color: #ff0000; }
.csharpcode_ajay1 .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode_ajay1 .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; To use above code we need to add COM reference to the mscoree.tlb to the project. mscoree.tlb can be located at: 
  &lt;br /&gt;&amp;quot;C:\WINDOWS\Microsoft.NET\Framework\vXXXXXX\mscoree.tlb&amp;quot;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;For more information, please refer to: &lt;a href="http://blogs.msdn.com/jackg/archive/2007/06/11/enumerating-appdomains.aspx"&gt;http://blogs.msdn.com/jackg/archive/2007/06/11/enumerating-appdomains.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9930356" width="1" height="1"&gt;</content><author><name>Ajay Bandooni</name><uri>http://blogs.msdn.com/members/Ajay+Bandooni.aspx</uri></author></entry><entry><title>Excel: How do you use RefEdit/range selection control to select a cell range using .Net</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/10/02/excel-how-do-you-use-refedit-range-selection-control-to-select-a-cell-range-using-net.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/10/02/excel-how-do-you-use-refedit-range-selection-control-to-select-a-cell-range-using-net.aspx</id><published>2009-10-02T20:33:00Z</published><updated>2009-10-02T20:33:00Z</updated><content type="html">&lt;P&gt;In Excel VBA, we could use RefEdit control on a user form for allowing users to select a cell range on worksheets. This control allows users to select a range easily just by dragging on Excel cells and it can be passed as an input (as range object) to the program. It is very beneficial for users while doing Excel programming using VBA, as user does not require typing the address of a range manually.&lt;/P&gt;
&lt;P&gt;However, we cannot use this control in other than VBA userforms, because RefEdit is not really a true ActiveX control, it is a special in-process to Excel only control that directly integrates with VBA. As per the following article, the RefEdit Control is designed to work only when placed on a form in an Excel VBA project.&lt;/P&gt;
&lt;P&gt;RefEdit control does not work on form in a Com Add-In in Excel&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.microsoft.com/?id=281542" mce_href="http://support.microsoft.com/?id=281542"&gt;http://support.microsoft.com/?id=281542&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;As a workaround, some people develop their own user control to achieve this functionality in Excel. However, if we want to use an Excel out of box option to implement such functionality in our .Net applications or any external Excel automation applications, here is what we need to do,&lt;/P&gt;
&lt;P&gt;We could make use of &lt;A href="http://msdn.microsoft.com/en-us/library/aa195768(office.11).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa195768(office.11).aspx"&gt;Application.Inputbox&lt;/A&gt; method that Excel Object Model exposes with the Type argument (which is last argument) set as 8. This allows us to select a cell range, as if we select while using RefEdit control/Function Arguments dialog box, which we get when we insert Excel functions&lt;/P&gt;
&lt;P&gt;I have implemented this using the C# code snippet below,&lt;/P&gt;&lt;PRE class=om_csharp_1&gt;            Excel.Application xlApp = &lt;SPAN class=str&gt;"&amp;lt;Refer to an Excel application instance&amp;gt;"&lt;/SPAN&gt;;
            &lt;SPAN class=rem&gt;//Declares range object&lt;/SPAN&gt;
            Microsoft.Office.Interop.Excel.Range rng;

            &lt;SPAN class=rem&gt;//Implements InputBox method with last argument value is set as 8&lt;/SPAN&gt;
            rng = (Microsoft.Office.Interop.Excel.Range)xlApp.InputBox(&lt;SPAN class=str&gt;"Select Range"&lt;/SPAN&gt;, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, 8);

            &lt;SPAN class=rem&gt;//Display the range address that we just received as an input using InputBox method&lt;/SPAN&gt;
            MessageBox.Show(rng.get_Address(System.Type.Missing, System.Type.Missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, System.Type.Missing, System.Type.Missing));&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;


.om_csharp_1, .om_csharp_1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	overflow-x:auto;
	overflow-y:auto;
	/*white-space: pre;*/
}
.om_csharp_1 pre { margin: 0em; }
.om_csharp_1 .rem { color: #008000; }
.om_csharp_1 .kwrd { color: #0000ff; }
.om_csharp_1 .str { color: #ff0000; }
.om_csharp_1 .op { color: #0000c0; }
.om_csharp_1 .preproc { color: #cc6633; }
.om_csharp_1 .asp { background-color: #ffff00; }
.om_csharp_1 .html { color: #800000; }
.om_csharp_1 .attr { color: #ff0000; }
.om_csharp_1 .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.om_csharp_1 .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902481" width="1" height="1"&gt;</content><author><name>Obuli Mani J</name><uri>http://blogs.msdn.com/members/Obuli+Mani+J.aspx</uri></author><category term="HowTo" scheme="http://blogs.msdn.com/vsod/archive/tags/HowTo/default.aspx" /><category term="COM AddIns" scheme="http://blogs.msdn.com/vsod/archive/tags/COM+AddIns/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/vsod/archive/tags/Excel/default.aspx" /></entry><entry><title>Excel: How do you implement Application_Quit event in Excel/how do you intercept Excel application Quit</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/10/02/blog-idea-how-do-you-implement-application-quit-event-in-excel-how-do-you-intercept-excel-application-quit.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/10/02/blog-idea-how-do-you-implement-application-quit-event-in-excel-how-do-you-intercept-excel-application-quit.aspx</id><published>2009-10-02T20:27:00Z</published><updated>2009-10-02T20:27:00Z</updated><content type="html">&lt;P&gt;We know Word Object model provides an event handler called Application_Quit, which will be triggered when the application quits, but we don’t have any such events for Excel (even for PowerPoint and some other Office applications). In order to workaround this issue, first thing that will come in our mind is to use an Office COM add-in and implement &lt;A href="http://msdn.microsoft.com/en-us/library/extensibility.idtextensibility2.onbeginshutdown(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/extensibility.idtextensibility2.onbeginshutdown(VS.80).aspx"&gt;OnBeginShutdown&lt;/A&gt; method (which “IDTExtensibility2” interface exposes). Moreover, this can be implemented for any/multiple Office applications as well. Otherwise, we can even use &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.addin.shutdown.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.addin.shutdown.aspx"&gt;ThisAddIn_Shutdown&lt;/A&gt; method that VSTO Application level add-in provides.&lt;/P&gt;
&lt;P&gt;However, all these methods can run some code when the application is being shut down and they do not allow us to control the quitting of the application. Let us assume a scenario, what if we need to intercept the application quit and need to decide whether to quit the application or not based on certain criteria/business rules.&lt;/P&gt;
&lt;P&gt;Here I come with an option to use the old style of processing &lt;A href="http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx#windows_messages" mce_href="http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx#windows_messages"&gt;Windows messages&lt;/A&gt; that Office applications receive. I have described the steps below to implement this thought for Excel using VB.Net COM Add-in in much simpler way.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here are the steps:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create an &lt;A href="http://support.microsoft.com/kb/302901" mce_href="http://support.microsoft.com/kb/302901"&gt;Excel COM Add-in using VB.Net&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;In order to process the windows messages that an Office application receives, we need to inherit the Connect class (Connect.vb) of the COM add-in from, &lt;EM&gt;System.Windows.Forms.NativeWindow&lt;/EM&gt; class. This class provides an overridable method called, &lt;EM&gt;WndProc()&lt;/EM&gt;, that passes Windows message as an argument. We can make use of these messages to implement, as we want. To inherit the &lt;EM&gt;NativeWindow&lt;/EM&gt; class in our Connect class, please make sure that you have added reference for &lt;EM&gt;System.Windows.Forms&lt;/EM&gt; &lt;/LI&gt;
&lt;LI&gt;Then, add the following Using statements in the Connect.cs module, &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;Imports&lt;/SPAN&gt; Extensibility
&lt;SPAN class=kwrd&gt;Imports&lt;/SPAN&gt; System.Runtime.InteropServices
&lt;SPAN class=kwrd&gt;Imports&lt;/SPAN&gt; System.Windows.Forms
&lt;SPAN class=kwrd&gt;Imports&lt;/SPAN&gt; Excel = Microsoft.Office.Interop.Excel&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Declare the following constant. It is the value for “Window Close” message, which will be passed by Excel when user clicks close button &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;Const&lt;/SPAN&gt; WM_CLOSE &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = 16&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Add the following code in the &lt;EM&gt;OnConnection&lt;/EM&gt; method of the Connect class. The main purpose of using this method is to pass the Excel application’s handle to &lt;EM&gt;NativeWindow&lt;/EM&gt; class so that it can process the messages that the application receives through the &lt;EM&gt;WndProc&lt;/EM&gt; method &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; OnConnection(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; application &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; connectMode &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Extensibility.ext_ConnectMode, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; addInInst &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByRef&lt;/SPAN&gt; custom &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; System.Array) &lt;SPAN class=kwrd&gt;Implements&lt;/SPAN&gt; Extensibility.IDTExtensibility2.OnConnection

&lt;SPAN class=rem&gt;'Type cast the application object to Excel application class&lt;/SPAN&gt;
xlApp = &lt;SPAN class=kwrd&gt;DirectCast&lt;/SPAN&gt;(application, Excel.Application)

&lt;SPAN class=rem&gt;'Pass the Excel application handle to NativeWindow class in order to process messages that Excel receives&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;MyBase&lt;/SPAN&gt;.AssignHandle(xlApp.Hwnd)

&lt;SPAN class=rem&gt;'To display a message box&lt;/SPAN&gt;
MessageBox.Show(&lt;SPAN class=str&gt;"Excel quit detection add-in started!"&lt;/SPAN&gt;)

&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Copy the following WndProc method implementation to trap the close action in Excel &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;Protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Overrides&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; WndProc(&lt;SPAN class=kwrd&gt;ByRef&lt;/SPAN&gt; m &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; System.Windows.Forms.Message)

        &lt;SPAN class=rem&gt;'Check if the Window handle passed by this procedure is for Excel application and the message is to indicate closing Excel application&lt;/SPAN&gt;
      
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; m.HWnd = xlApp.Hwnd &lt;SPAN class=kwrd&gt;And&lt;/SPAN&gt; m.Msg = WM_CLOSE &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; wb &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Excel.Workbook

            &lt;SPAN class=rem&gt;'Prompt Message box to close Excel or not&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; res &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; DialogResult = MessageBox.Show(&lt;SPAN class=str&gt;"You are quitting Excel. Do you want to save changes for the workbooks opened?"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"Excel Quit"&lt;/SPAN&gt;, MessageBoxButtons.YesNoCancel, MessageBoxIcon.&lt;SPAN class=kwrd&gt;Error&lt;/SPAN&gt;, MessageBoxDefaultButton.Button1)

&lt;SPAN class=rem&gt;'If the user response is "Yes" for the message box, then loop through all the workbooks, save and close it&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; res = DialogResult.Yes &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; wb &lt;SPAN class=kwrd&gt;In&lt;/SPAN&gt; xlApp.Workbooks
wb.Close(&lt;SPAN class=kwrd&gt;True&lt;/SPAN&gt;)
&lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;MyBase&lt;/SPAN&gt;.WndProc(m) &lt;SPAN class=rem&gt;'process message as default&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;ElseIf&lt;/SPAN&gt; res = DialogResult.No &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt; &lt;SPAN class=rem&gt;'If no, Loop through all the workbooks and close it, but don't save&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; wb &lt;SPAN class=kwrd&gt;In&lt;/SPAN&gt; xlApp.Workbooks
  wb.Close(&lt;SPAN class=kwrd&gt;False&lt;/SPAN&gt;)
&lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;MyBase&lt;/SPAN&gt;.WndProc(m) &lt;SPAN class=rem&gt;'process message as default&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;

&lt;SPAN class=rem&gt;'If none of the above criteria is not satisfied, Excel will not quit&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;Else&lt;/SPAN&gt;

            &lt;SPAN class=kwrd&gt;MyBase&lt;/SPAN&gt;.WndProc(m) &lt;SPAN class=rem&gt;'process message as default&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Build the add-in and run it. Now, Excel will prompt with a message box, when user attempts to close Excel application by either clicking “X” button or by going to File menu--&amp;gt;Exit or by pressing Alt+F4. &lt;/LI&gt;&lt;/OL&gt;
&lt;STYLE type=text/css&gt;




.om_csharp_1
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	overflow-x:auto;
	overflow-y:auto;
	/*white-space: pre;*/
}

.om_csharp_1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.om_csharp_1 pre { margin: 0em; }
.om_csharp_1 .rem { color: #008000; }
.om_csharp_1 .kwrd { color: #0000ff; }
.om_csharp_1 .str { color: #ff0000; }
.om_csharp_1 .op { color: #0000c0; }
.om_csharp_1 .preproc { color: #cc6633; }
.om_csharp_1 .asp { background-color: #ffff00; }
.om_csharp_1 .html { color: #800000; }
.om_csharp_1 .attr { color: #ff0000; }
.om_csharp_1 .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.om_csharp_1 .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902477" width="1" height="1"&gt;</content><author><name>Obuli Mani J</name><uri>http://blogs.msdn.com/members/Obuli+Mani+J.aspx</uri></author><category term="HowTo" scheme="http://blogs.msdn.com/vsod/archive/tags/HowTo/default.aspx" /><category term="COM AddIns" scheme="http://blogs.msdn.com/vsod/archive/tags/COM+AddIns/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/vsod/archive/tags/Excel/default.aspx" /></entry><entry><title>Excel: How to run C# code behind with a click of a button on a Worksheet, without VBA code</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/10/02/excel-how-to-run-c-code-behind-with-a-click-of-a-button-on-a-worksheet-without-vba-code.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/10/02/excel-how-to-run-c-code-behind-with-a-click-of-a-button-on-a-worksheet-without-vba-code.aspx</id><published>2009-10-02T19:59:00Z</published><updated>2009-10-02T19:59:00Z</updated><content type="html">&lt;P&gt;OLE object controls such as Command button, Checkbox, etc., allow us to call VBA code behind using OnAction property. However, when a situation arises that we have to call .Net code behind, we cannot use OnAction property, because this property requires a VBA macro to be assigned. In such situations, the option that we can immediately think of is to have VBA macro to call the .Net code, which is possible. &lt;/P&gt;
&lt;P&gt;There are scenarios such as one where you want to upgrade your VBA add-in (XLA) to .Net COM/Automation add-in (with no VBA layer in between), which does not allow us to use OnAction property, then this blog post can help you. Because this option does not require us to have VBA layer in between and we can call C#.Net code directly.&lt;/P&gt;
&lt;P&gt;I have illustrated this idea using an Excel COM add-in that inserts an OLE command button control on Application start up and I will use it to call its button click event written in C# code behind. To know how to build an Office COM add-in by using Visual C# .NET, please refer to the article, &lt;A href="http://support.microsoft.com/kb/302901" mce_href="http://support.microsoft.com/kb/302901"&gt;http://support.microsoft.com/kb/302901&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here are the steps:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create an &lt;A href="http://support.microsoft.com/kb/302901" mce_href="http://support.microsoft.com/kb/302901"&gt;Excel COM Add-in using C#&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Add the following Using statements in the Connect.cs class, &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; Extensibility;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Runtime.InteropServices;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; Excel = Microsoft.Office.Interop.Excel;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; Office = Microsoft.Office.Core;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; MSForms = Microsoft.Vbe.Interop.Forms;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; Microsoft.VisualBasic.CompilerServices;&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Add the following code in the OnConnection method of the Connect class. This code will insert a command button onto the Active Worksheet and wire up the Click event for the button, which is written in the C# code behind &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; OnConnection(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; application, Extensibility.ext_ConnectMode connectMode, &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; addInInst, &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; System.Array custom)
    &amp;nbsp; {
            &lt;SPAN class=kwrd&gt;try&lt;/SPAN&gt;
            {
                
                xlApp = (Excel.Application)application;
                wbs = xlApp.Workbooks; &lt;SPAN class=rem&gt;//Get the Workbooks collection&lt;/SPAN&gt;
                wbs.Add(Type.Missing); &lt;SPAN class=rem&gt;//Add a new workbook&lt;/SPAN&gt;
                wb = xlApp.ActiveWorkbook; 
                wsht = (Excel.Worksheet)wb.ActiveSheet;
                &lt;SPAN class=rem&gt;//To insert an OLE Object which of type "CommandButton". We need to use the ProgID for the command button, which is "Forms.CommandButton.1"&lt;/SPAN&gt;
                cmdButton = (Excel.Shape)wsht.Shapes.AddOLEObject(&lt;SPAN class=str&gt;"Forms.CommandButton.1"&lt;/SPAN&gt;, Type.Missing, &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;, Type.Missing, Type.Missing, Type.Missing, 200, 100, 100, 100);
                &lt;SPAN class=rem&gt;//We name the command button, we will use it later&lt;/SPAN&gt;
                cmdButton.Name = &lt;SPAN class=str&gt;"btnClick"&lt;/SPAN&gt;;
                &lt;SPAN class=rem&gt;//In order to access the Command button object, we are using NewLateBinding class as below&lt;/SPAN&gt;
                CmdBtn = (MSForms.CommandButton)NewLateBinding.LateGet((Excel.Worksheet)xlApp.ActiveSheet, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"btnClick"&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt;[0], &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;);
                
                &lt;SPAN class=rem&gt;//Set the required properties for the command button&lt;/SPAN&gt;
                CmdBtn.FontSize = 10;
                CmdBtn.FontBold = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;; 
                CmdBtn.Caption = &lt;SPAN class=str&gt;"Click Me"&lt;/SPAN&gt;;
                &lt;SPAN class=rem&gt;//Wiring up the Click event&lt;/SPAN&gt;
                CmdBtn.Click += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Microsoft.Vbe.Interop.Forms.CommandButtonEvents_ClickEventHandler(CmdBtn_Click);
                
                }
            &lt;SPAN class=kwrd&gt;catch&lt;/SPAN&gt; (Exception ex)
            {

                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
       }&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Now, we will need to implement the Button Click event handler. Here is the sample code snippet that just displays a message box and writes value to some cells &lt;PRE class=om_csharp_1&gt;&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; CmdBtn_Click()
{
            &lt;SPAN class=rem&gt;//Adding the event code&lt;/SPAN&gt;
            System.Windows.Forms.MessageBox.Show(&lt;SPAN class=str&gt;"I am called from C# COM add-in"&lt;/SPAN&gt;);
            wsht.get_Range(&lt;SPAN class=str&gt;"A1"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"A10"&lt;/SPAN&gt;).Value2 = &lt;SPAN class=str&gt;"I am called from C# Add-in"&lt;/SPAN&gt;;  
}&lt;/PRE&gt;&lt;/LI&gt;
&lt;LI&gt;Compile and Build the project, which will add some registry entries to notify Office to load the add-in. 
&lt;P&gt;(Note: on machines with Vista or later, you will need to launch Visual Studio in Administrator mode (To do that, right click Visual Studio Icon--&amp;gt;Run as Administrator), as Vista or later would not allow a program to modify registry entries, when &lt;A href="http://technet.microsoft.com/en-us/library/cc709691(WS.10).aspx" mce_href="http://technet.microsoft.com/en-us/library/cc709691(WS.10).aspx"&gt;UAC&lt;/A&gt; is turned on)&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;Now, the add-in will add a button and upon button click, it will call code from the C# code behind &lt;/LI&gt;&lt;/OL&gt;
&lt;STYLE type=text/css&gt;
.om_csharp_1, 
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
	overflow-x:auto;
	overflow-y:auto;
}
.om_csharp_1, .om_csharp_1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.om_csharp_1 pre { margin: 0em; }
.om_csharp_1 .rem { color: #008000; }
.om_csharp_1 .kwrd { color: #0000ff; }
.om_csharp_1 .str { color: #ff0000; }
.om_csharp_1 .op { color: #0000c0; }
.om_csharp_1 .preproc { color: #cc6633; }
.om_csharp_1 .asp { background-color: #ffff00; }
.om_csharp_1 .html { color: #800000; }
.om_csharp_1 .attr { color: #ff0000; }
.om_csharp_1 .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.om_csharp_1 .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902451" width="1" height="1"&gt;</content><author><name>Obuli Mani J</name><uri>http://blogs.msdn.com/members/Obuli+Mani+J.aspx</uri></author><category term="HowTo" scheme="http://blogs.msdn.com/vsod/archive/tags/HowTo/default.aspx" /><category term="COM AddIns" scheme="http://blogs.msdn.com/vsod/archive/tags/COM+AddIns/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/vsod/archive/tags/Excel/default.aspx" /></entry><entry><title>Word: How to do “Drag and Drop” of Content controls from Task Pane to the document</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/10/02/word-how-to-do-drag-and-drop-of-content-controls-from-task-pane-to-the-document.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/10/02/word-how-to-do-drag-and-drop-of-content-controls-from-task-pane-to-the-document.aspx</id><published>2009-10-02T18:44:00Z</published><updated>2009-10-02T18:44:00Z</updated><content type="html">&lt;OL&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;Create a Word VSTO application level project for Word using Visual Studio 2008/2005 (For VS 2005, you need to install &lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=5E86CAB3-6FD6-4955-B979-E1676DB6B3CB&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?familyid=5E86CAB3-6FD6-4955-B979-E1676DB6B3CB&amp;amp;displaylang=en"&gt;VSTO SE&lt;/A&gt;). To do that, go to File Menu in VS --&amp;gt;New--&amp;gt;Project--&amp;gt;Expand Office hive--&amp;gt;Select Word 2007 Add-in&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;Add a user control item (Name it as CTP.cs) to the project and insert a List box (Name it as, lstItems). To add a user control to the project, go to Project Menu--&amp;gt;Add User Control--&amp;gt;Name it as CTP.cs&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;Add the code snippet below in the ThisAddIn_Startup event (You will see this when you view the code for ThisAddin.cs).&amp;nbsp; This will add our custom task pane while loading Word&lt;/DIV&gt;
&lt;DIV class=om_csharp_1&gt;&lt;PRE class=alt&gt;        Microsoft.Office.Tools.CustomTaskPane WCTP; &lt;/PRE&gt;&lt;PRE&gt;        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; ThisAddIn_Startup(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, System.EventArgs e)&lt;/PRE&gt;&lt;PRE class=alt&gt;        {&lt;/PRE&gt;&lt;PRE&gt;           &lt;SPAN class=rem&gt;//To add our CTP to the Custom Task panes collection of Word. We need to set the Visible property to true, otherwise, by&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;           &lt;SPAN class=rem&gt;//default it is false&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;WCTP = (Microsoft.Office.Tools.CustomTaskPane)&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.CustomTaskPanes.Add(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; CTP(), &lt;SPAN class=str&gt;"Do Drag Drop"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alt&gt;            WCTP.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;        }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;The code snippet that we need to have in the user control class is as below, 
&lt;DIV class=om_csharp_1&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Collections.Generic;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.ComponentModel;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Drawing;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Data;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Linq;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Text;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Forms;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; Word = Microsoft.Office.Interop.Word;&lt;/PRE&gt;&lt;PRE&gt;  &lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;namespace&lt;/SPAN&gt; DragDrop_ContentControls&lt;/PRE&gt;&lt;PRE&gt;{&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; CTP : UserControl&lt;/PRE&gt;&lt;PRE&gt;    {&lt;/PRE&gt;&lt;PRE class=alt&gt;        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; CTP()&lt;/PRE&gt;&lt;PRE&gt;        {&lt;/PRE&gt;&lt;PRE class=alt&gt;            InitializeComponent();&lt;/PRE&gt;&lt;PRE&gt;        }&lt;/PRE&gt;&lt;PRE class=alt&gt;        &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; missing = System.Type.Missing;&lt;/PRE&gt;&lt;PRE&gt;        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; Rectangle dragBoxFromMouseDown;&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; lstItems_MouseDown(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)&lt;/PRE&gt;&lt;PRE&gt;        {&lt;/PRE&gt;&lt;PRE class=alt&gt;                &lt;SPAN class=rem&gt;// Remember the point where the mouse down occurred. The DragSize indicates&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                &lt;SPAN class=rem&gt;// the size that the mouse can move before a drag event should be started.                &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;                Size dragSize = SystemInformation.DragSize;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;                &lt;SPAN class=rem&gt;// Create a rectangle using the DragSize, with the mouse position being&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                &lt;SPAN class=rem&gt;// at the center of the rectangle.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;                dragBoxFromMouseDown = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Rectangle(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Point(e.X - (dragSize.Width / 2),&lt;/PRE&gt;&lt;PRE&gt;                                                               e.Y - (dragSize.Height / 2)), dragSize); &lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;        }&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; lstItems_MouseMove(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)&lt;/PRE&gt;&lt;PRE class=alt&gt;        {&lt;/PRE&gt;&lt;PRE&gt;            &lt;/PRE&gt;&lt;PRE class=alt&gt;                                                                &lt;SPAN class=rem&gt;//To check if the Mouse left button is clicked&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; ((e.Button &amp;amp; MouseButtons.Left) == MouseButtons.Left)&lt;/PRE&gt;&lt;PRE class=alt&gt;            {&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;                &lt;SPAN class=rem&gt;// If the mouse moves outside the rectangle, start the drag.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (dragBoxFromMouseDown != Rectangle.Empty &amp;amp;&amp;amp;&lt;/PRE&gt;&lt;PRE class=alt&gt;                    !dragBoxFromMouseDown.Contains(e.X, e.Y))&lt;/PRE&gt;&lt;PRE&gt;                {&lt;/PRE&gt;&lt;PRE class=alt&gt;                            &lt;SPAN class=rem&gt;//Start Drag Drop&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                            DoDragDrop(&lt;SPAN class=str&gt;""&lt;/SPAN&gt;, DragDropEffects.All);&lt;/PRE&gt;&lt;PRE class=alt&gt;                            Word.ContentControl cntCtrl;&lt;/PRE&gt;&lt;PRE&gt;                            &lt;/PRE&gt;&lt;PRE class=alt&gt;                            &lt;SPAN class=rem&gt;//Insert Content Control at the selected range&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                            cntCtrl = Globals.ThisAddIn.Application.Selection.Range.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing);&lt;/PRE&gt;&lt;PRE class=alt&gt;                            cntCtrl.Range.Text = lstItems.Text; &lt;SPAN class=rem&gt;//This is how we set the value to be to populated in the content controls&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;                            &lt;SPAN class=rem&gt;//To set the XPath for custom XML binding for content controls. This is optional&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;                            &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; xPath = &lt;SPAN class=str&gt;@"Root\" &lt;/SPAN&gt;+ lstItems.Text.Replace(&lt;SPAN class=str&gt;" "&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"_"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE&gt;                            cntCtrl.XMLMapping.SetMapping(xPath, "&lt;/SPAN&gt;", &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;); &lt;SPAN class=rem&gt;//This is required when you want to bind to a custom XML part&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;                    }&lt;/PRE&gt;&lt;PRE class=alt&gt;                }&lt;/PRE&gt;&lt;PRE&gt;            &lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;        }&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; lstItems_MouseUp(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)&lt;/PRE&gt;&lt;PRE class=alt&gt;        {&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;            &lt;SPAN class=rem&gt;// Reset the drag rectangle when the mouse button is raised.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;            dragBoxFromMouseDown = Rectangle.Empty;&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;        }&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;    }&lt;/PRE&gt;&lt;PRE class=alt&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;Build the application and Run it to launch Word &lt;/LI&gt;
&lt;LI&gt;When you drag an item from List box in the Task Pane onto the document surface, you will see a content control being added with the caption of the list item name &lt;/LI&gt;&lt;/OL&gt;
&lt;STYLE type=text/css&gt;



.om_csharp_1,
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
	overflow-x:auto;
	overflow-y:auto;
}

.om_csharp_1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.om_csharp_1 pre { margin: 0em; }
.om_csharp_1 .rem { color: #008000; }
.om_csharp_1 .kwrd { color: #0000ff; }
.om_csharp_1 .str { color: #ff0000; }
.om_csharp_1 .op { color: #0000c0; }
.om_csharp_1 .preproc { color: #cc6633; }
.om_csharp_1 .asp { background-color: #ffff00; }
.om_csharp_1 .html { color: #800000; }
.om_csharp_1 .attr { color: #ff0000; }
.om_csharp_1 .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902413" width="1" height="1"&gt;</content><author><name>Obuli Mani J</name><uri>http://blogs.msdn.com/members/Obuli+Mani+J.aspx</uri></author><category term="VSTO" scheme="http://blogs.msdn.com/vsod/archive/tags/VSTO/default.aspx" /><category term="HowTo" scheme="http://blogs.msdn.com/vsod/archive/tags/HowTo/default.aspx" /><category term="Word" scheme="http://blogs.msdn.com/vsod/archive/tags/Word/default.aspx" /></entry><entry><title>Issue: Change in behavior from Office 2007 RTM to SP2 when Sheet.Unprotect is called</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/09/11/issue-change-in-behavior-from-office-2007-rtm-to-sp2-when-sheet-unprotect-is-called.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/09/11/issue-change-in-behavior-from-office-2007-rtm-to-sp2-when-sheet-unprotect-is-called.aspx</id><published>2009-09-11T23:11:00Z</published><updated>2009-09-11T23:11:00Z</updated><content type="html">&lt;P&gt;Let’s say you have a password protected Excel workbook, and you are calling following function through VBA in it:&lt;/P&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; FONT-FAMILY: 'Courier New'"&gt;  Sheet.Unprotect Password:=&lt;SPAN style="COLOR: #ff0000"&gt;""&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;If you run this macro in Office 2007 RTM or SP1 version, it will result in a VBA Error; provided the actual password is not an empty string. However, in SP2 it will result in a password input dialog box.&lt;/P&gt;
&lt;P&gt;This change of behavior is the&amp;nbsp;result of a design change for SP2 release.&lt;/P&gt;
&lt;P&gt;In case you have a code/logic which depends on the handling of VBA Error received in Office 2007 RTM/SP1 for wrong password specified for the above call, you can get the same behavior in SP2 release by passing a dummy password instead of an empty string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; FONT-FAMILY: 'Courier New'"&gt;  Sheet.Unprotect Password:=&lt;SPAN style="COLOR: #ff0000"&gt;"dummy"&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;If the specified string is the correct password then the Sheet will be unprotected without any error or showing the Password input dialog box.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9894364" width="1" height="1"&gt;</content><author><name>manvir.singh</name><uri>http://blogs.msdn.com/members/manvir.singh.aspx</uri></author><category term="Excel" scheme="http://blogs.msdn.com/vsod/archive/tags/Excel/default.aspx" /><category term="SP2" scheme="http://blogs.msdn.com/vsod/archive/tags/SP2/default.aspx" /></entry><entry><title>Issue: Formatting individual characters of Data Labels of Charts programmatically in Excel 2007 SP2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/09/11/issue-formatting-individual-characters-of-data-labels-of-charts-programmatically-in-excel-2007-sp2.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/09/11/issue-formatting-individual-characters-of-data-labels-of-charts-programmatically-in-excel-2007-sp2.aspx</id><published>2009-09-11T19:21:00Z</published><updated>2009-09-11T19:21:00Z</updated><content type="html">&lt;P&gt;If you are working with Charts programmatically in Excel 2007 Service Pack 2, and are trying to set the formatting of individual characters of Data Labels of charts programmatically, you will notice that the formatting gets applied to the whole of Data Label instead of the specific character/range.&lt;/P&gt;
&lt;P&gt;Here is a snippet which one would typically be used to set formatting of specific characters:&lt;/P&gt;&lt;PRE class=ms_vbcode_1&gt;&lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; Test()
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; ch &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Chart
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; series &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; series
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; points &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; points
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; label &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; DataLabel
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; chars &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Characters
    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; font &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; font
    
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; ch = ActiveSheet.Shapes(1).Chart
    
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; series = ch.SeriesCollection(1)
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; points = series.points
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; label = points(1).DataLabel
    
    label.Text = label.Text &amp;amp; vbCrLf &amp;amp; &lt;SPAN class=str&gt;"a"&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; chars = label.Characters(3, 1)
    
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; font = chars.font
    
    font.Size = 24
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;P&gt;The above code will work as desired (format individual characters) on Excel 2003 and Excel 2007 Service Pack 1 releases.&lt;/P&gt;
&lt;P&gt;This behavior is a known bug with Excel 2007 Service Pack 2 release, and the Excel development team is looking into it. Unfortunately, there is no known programmatic workaround possible for this requirement. Character level formatting of Data labels can only be set manually as of now.&lt;/P&gt;
&lt;STYLE type=text/css&gt;



.ms_vbcode_1, .ms_vbcode_1 pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.ms_vbcode_1 pre { margin: 0em; }
.ms_vbcode_1 .rem { color: #008000; }
.ms_vbcode_1 .kwrd { color: #0000ff; }
.ms_vbcode_1 .str { color: #ff0000; }
.ms_vbcode_1 .op { color: #0000c0; }
.ms_vbcode_1 .preproc { color: #cc6633; }
.ms_vbcode_1 .asp { background-color: #ffff00; }
.ms_vbcode_1 .html { color: #800000; }
.ms_vbcode_1 .attr { color: #ff0000; }
.ms_vbcode_1 .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.ms_vbcode_1 .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9894263" width="1" height="1"&gt;</content><author><name>manvir.singh</name><uri>http://blogs.msdn.com/members/manvir.singh.aspx</uri></author><category term="Charts" scheme="http://blogs.msdn.com/vsod/archive/tags/Charts/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/vsod/archive/tags/Excel/default.aspx" /><category term="SP2" scheme="http://blogs.msdn.com/vsod/archive/tags/SP2/default.aspx" /></entry><entry><title>WORD 2003/EXCEL 2003: VSTO Customization added using ServerDocument.AddCustomization method does not add customization if your document contained an embedded VSTO customized Document/WorkBook</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/30/word-2003-excel-2003-vsto-customization-added-using-serverdocument-addcustomization-method-does-not-add-customization-if-your-document-contained-an-embedded-vsto-customized-document-workbook.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/30/word-2003-excel-2003-vsto-customization-added-using-serverdocument-addcustomization-method-does-not-add-customization-if-your-document-contained-an-embedded-vsto-customized-document-workbook.aspx</id><published>2009-06-30T14:23:30Z</published><updated>2009-06-30T14:23:30Z</updated><content type="html">&lt;h5&gt;PROBLEM DESCRIPTION&lt;/h5&gt;  &lt;p&gt;Consider this scenario. You are adding VSTO customizations dynamically to Word 2003/Excel 2003 documents using &lt;em&gt;ServerDocument.AddCustomization&lt;/em&gt; method.&amp;#160; The&lt;em&gt; ServerDocument.AddCustomization&lt;/em&gt; method succeeds. But when you try to open this customized document, the customization does not load. If you have the “&lt;em&gt;VSTO_SUPPRESSDISPLAYALERTS&lt;/em&gt;” environment variable set to “0” you will get the following error:&amp;#160; “The customization assembly could not be found or could not be loaded.” &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/WOR.AddCustomizationmethoddoesnotaddcust_EB2A/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/WOR.AddCustomizationmethoddoesnotaddcust_EB2A/clip_image002_thumb.jpg" width="359" height="253" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This is a known issue with Word 2003 and Excel 2003 VSTO customizations, containing embedded customized documents. It doesn’t occur with Word 2007 (or Excel 2007) VSTO customization.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;How to avoid this?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;To workaround this issue, you can add the customization to the outer document using VSTO related document properties. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;_AssemblyName:&amp;#160; &lt;/b&gt;This property contains an asterisk (*). This indicates to the Microsoft Office application that the document has a Visual Studio Tools for Office customization. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;_AssemblyLocation: &lt;/b&gt;This property contains a string that provides details about the deployment manifest for the customization. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For more details on document properties, please visit &lt;a href="http://msdn.microsoft.com/en-us/library/ds87aeyf.aspx"&gt;Custom Document Properties Overview&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The _AssemblyLocation custom document property needs to point to the deployment manfiest location. In order to generate the deployment manifest, follow these steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open the Solution that you would like to publish using Visual Studio&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;Click&amp;#160; on the View, Select Solution Explorer (This will display Solution explorer window) &lt;/li&gt;    &lt;li&gt;Right-click the project node in Solution Explorer. &lt;/li&gt;    &lt;li&gt;Click &lt;b&gt;Publish&lt;/b&gt; on the shortcut menu. &lt;/li&gt;    &lt;li&gt;The &lt;b&gt;Publish Wizard&lt;/b&gt; appears. &lt;/li&gt;    &lt;li&gt;In the Specify the location to &lt;b&gt;publish&lt;/b&gt; this application box, type the path to the folder where you want to deploy the solution. Optionally, you can click Browse and navigate to the folder using the dialog box that appears. &lt;/li&gt;    &lt;li&gt;Verify that the path is correct, and then click &lt;b&gt;Finish&lt;/b&gt;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The document, assemblies, and manifests are copied to the publish location, with the assemblies and application manifest (&amp;lt;filename&amp;gt;.dll.mainfest) in a subdirectory under the document and deployment manifest (&amp;lt;filename&amp;gt;.application)&lt;/p&gt;  &lt;p&gt;For more details please refer to:&lt;u&gt; &lt;/u&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ka36ec41.aspx"&gt;How to: Deploy Solution Files Using the Publish Wizard (2003 System)&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;You can add these custom document properties using either of the two approaches:-&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Use &lt;b&gt;IPropertyStorage&lt;/b&gt; APIs to add the custom properties. &lt;/li&gt;    &lt;li&gt;Add the custom properties using Word/Excel Object Model (Please see KB 257757 if you intend to do this task from un-attended environments). &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Approach 1: Adding Custom Document Properties programmatically using IPropertyStorage&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The other approach that you can use is to add the properties using &lt;b&gt;IPropertyStorage i&lt;/b&gt;nterface.&lt;b&gt; &lt;/b&gt;You can use the concepts demonstrated in DSOFile sample, to add the custom document properties. This sample can be downloaded using the link &lt;a href="http://support.microsoft.com/kb/224351"&gt;http://support.microsoft.com/kb/224351&lt;/a&gt;&lt;u&gt;. &lt;/u&gt;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;div style="background-color: white; font-family: calibri; font-size: 11px"&gt;Information about DSOFile:            &lt;br /&gt;The Dsofile.dll sample file demonstrates how to use the OLE32 IPropertyStorage interface to access the extended properties of OLE structured storage files. The component converts the data to Automation friendly data types for easier use by high level programming languages such as Visual Basic 6.0, Visual Basic .NET, and C#. The Dsofile.dll sample file is given with full source code and includes sample clients written in Visual Basic 6.0 and Visual Basic .NET 2003 (7.1).Warning The Dsofile.dll, the source code, and the associated samples are provided &amp;quot;as is&amp;quot; without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. Use at your own risk.&lt;/span&gt;             &lt;h6&gt;&lt;/h6&gt;         &lt;/div&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Let’s see how to use DSOFile sample to attach custom properties to the document, but before that we need to ensure that DSOFile.dll is registered on the development machine.&amp;#160; The self-extracting setup installs and registers the DsoFile.dll component in a location that you want.&amp;#160; But, if you move the DLL to another location or to another computer, you have to re-register the DLL before you can use it again. To do this, type &lt;b&gt;regsvr32 [filepath]\dsofile.dll&lt;/b&gt; in the &lt;b&gt;Run&lt;/b&gt; dialog box on the &lt;b&gt;Start&lt;/b&gt; menu (or from elevated rights command prompt in case of Vista).&lt;/p&gt;  &lt;p&gt;Let’s start by creating a new windows application project which references DSOFile.dll and adds these properties.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Launch Visual Studio &lt;/li&gt;    &lt;li&gt;On the File menu, point to New, and then click Project. &lt;/li&gt;    &lt;li&gt;In the Project Types pane, expand Visual C# or Visual Basic, and then Click on Windows. &lt;/li&gt;    &lt;li&gt;In the templates pane, select “Windows Form Application” &lt;/li&gt;    &lt;li&gt;In the Name box, type AddPropertiesSample &lt;/li&gt;    &lt;li&gt;Click OK. (This will open Visual Studio and by default one Window form &lt;b&gt;Form1&lt;/b&gt; will be added to the project) &lt;/li&gt;    &lt;li&gt;Click&amp;#160; on the View, Select Solution Explorer (This will display Solution explorer window) &lt;/li&gt;    &lt;li&gt;Right click on the References and Select “Add References…” from the drop down menu. &lt;/li&gt;    &lt;li&gt;The “Add Reference” dialog will be displayed, Click on the COM tab in the dialog. &lt;/li&gt;    &lt;li&gt;Locate “DSO OLE Document Properties Reader 2.1” in the Component Name and Click on OK. &lt;/li&gt;    &lt;li&gt;Click&amp;#160; on the View, Select ToolBox (This will display ToolBox) &lt;/li&gt;    &lt;li&gt;Expand “All Windows Forms” in the ToolBox &lt;/li&gt;    &lt;li&gt;Drag and Drop button control on the Form1, a new control named Button1 will be added to the form. &lt;/li&gt;    &lt;li&gt;Double click on the button1 to add button1_Click event, paste the following code      &lt;div class="csharpcode"&gt;       &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; fileName = &lt;span class="str"&gt;@&amp;quot;C:\temp\Sample.doc&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; vstoDocumentLocation = &lt;span class="str"&gt;@&amp;quot;C:\Temp\WordDocument.application&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;DSOFile.OleDocumentPropertiesClass doc = &lt;span class="kwrd"&gt;new&lt;/span&gt; DSOFile.OleDocumentPropertiesClass();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;doc.Open(fileName, &lt;span class="kwrd"&gt;false&lt;/span&gt;, DSOFile.dsoFileOpenOptions.dsoOptionDefault);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; assemblyName = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;DSOFile.CustomProperties customProperties = doc.CustomProperties;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="rem"&gt;//Check if _AssemblyName property already exists&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;  {&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;     DSOFile.CustomProperty nameProp = customProperties[&lt;span class="str"&gt;&amp;quot;_AssemblyName&amp;quot;&lt;/span&gt;];&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;     nameProp.set_Value(&lt;span class="kwrd"&gt;ref&lt;/span&gt; assemblyName);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;  }&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception)&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;  {&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;     customProperties.Add(&lt;span class="str"&gt;&amp;quot;_AssemblyName&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;ref&lt;/span&gt; assemblyName);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;  }&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&lt;span class="rem"&gt;//Check if _AssemblyLocation property already exists&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;  {&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;      DSOFile.CustomProperty loc = customProperties[&lt;span class="str"&gt;&amp;quot;_AssemblyLocation&amp;quot;&lt;/span&gt;];&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;      loc.set_Value(&lt;span class="kwrd"&gt;ref&lt;/span&gt; assemblyLocation);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;  }&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;  {&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;      customProperties.Add(&lt;span class="str"&gt;&amp;quot;_AssemblyLocation&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;ref&lt;/span&gt; vstoDocumentLocation);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;  }&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;doc.Save();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;doc.Close(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;
    &lt;/div&gt;
    &lt;style type="text/css"&gt;















.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;p&gt;&lt;b&gt;&lt;u&gt;Approach 2: Add the properties using Word/Excel Object Model:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

    &lt;p&gt;One more approach that you can use is to add the properties using Excel/Word object model. &lt;/p&gt;

    &lt;p&gt;Let’s start by creating a new windows application project which references Excel/Word libraries and adds these properties using &lt;i&gt;CustomDocumentProperties&lt;/i&gt; Object.&lt;/p&gt;

    &lt;p&gt;&lt;b&gt;Create an Automation Client for Microsoft Word&lt;/b&gt;&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;Start Visual Studio .NET. &lt;/li&gt;

      &lt;li&gt;On the &lt;b&gt;File&lt;/b&gt; menu, click &lt;b&gt;New&lt;/b&gt;, and then click &lt;b&gt;Project&lt;/b&gt;. Select &lt;b&gt;Windows Application&lt;/b&gt; from the Visual C# Project types. Form1 is created by default. &lt;/li&gt;

      &lt;li&gt;Add a reference to &lt;b&gt;Microsoft Word Object Library&lt;/b&gt;. To do this, follow these steps: 

        &lt;ol type="a"&gt;
          &lt;li&gt;On the &lt;b&gt;Project&lt;/b&gt; menu, click &lt;b&gt;Add Reference&lt;/b&gt;. &lt;/li&gt;

          &lt;li&gt;On the &lt;b&gt;COM&lt;/b&gt; tab, locate &lt;b&gt;Microsoft Word Object Library&lt;/b&gt;, and then click &lt;b&gt;Select&lt;/b&gt;. &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;

      &lt;li&gt;Click &lt;b&gt;OK&lt;/b&gt; in the &lt;b&gt;Add References&lt;/b&gt; dialog box to accept your selections. On the&lt;b&gt; View&lt;/b&gt; menu, select&lt;b&gt; Toolbox&lt;/b&gt; to display the Toolbox, and then add a button to Form1. &lt;/li&gt;

      &lt;li&gt;Double-click &lt;b&gt;Button1&lt;/b&gt;. The code window for the form appears. &lt;/li&gt;

      &lt;li&gt;In the code window, replace the following code 
        &lt;div class="csharpcode"&gt;
          &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; button1_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;}&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;With:-&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; button1_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;Word.Application oWord;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;Word._Document oDoc;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; oMissing = Missing.Value;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; oDocBuiltInProps;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; oDocCustomProps;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; fileName = &lt;span class="str"&gt;@&amp;quot;C:\test.doc&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;&lt;span class="rem"&gt;//Create an instance of Microsoft Word and make it visible.&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;oWord = &lt;span class="kwrd"&gt;new&lt;/span&gt; Word.Application();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;oWord.Visible = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;&lt;span class="rem"&gt;//Create a new Document and get the BuiltInDocumentProperties collection.&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;oDoc = oWord.Documents.Open(&lt;span class="kwrd"&gt;ref&lt;/span&gt; fileName,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;                            &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;                            &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;                            &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;                            &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;                            &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing);&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;oDocBuiltInProps = oDoc.BuiltInDocumentProperties;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;Type typeDocBuiltInProps = oDocBuiltInProps.GetType();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;&lt;span class="rem"&gt;//Get the Author property and display it.&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strName;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strValue;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;&lt;span class="rem"&gt;//Add a property/value pair to the CustomDocumentProperties collection.&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;oDocCustomProps = oDoc.CustomDocumentProperties;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; oDocAssemblyNameProp;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;Type typeDocAssemblyNameProp; &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;Type typeDocCustomProps = oDocCustomProps.GetType();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;strName = &lt;span class="str"&gt;&amp;quot;_AssemblyName&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;oDocAssemblyNameProp = typeDocCustomProps.InvokeMember(&lt;span class="str"&gt;&amp;quot;Item&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;                        BindingFlags.Default | BindingFlags.GetProperty, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;                        &lt;span class="kwrd"&gt;null&lt;/span&gt;, oDocCustomProps, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { strName });&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;typeDocAssemblyNameProp = oDocAssemblyNameProp.GetType();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;strValue = typeDocAssemblyNameProp.InvokeMember(&lt;span class="str"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;            BindingFlags.Default | BindingFlags.GetProperty, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  48:  &lt;/span&gt;            &lt;span class="kwrd"&gt;null&lt;/span&gt;, oDocAssemblyNameProp, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { }).ToString();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  49:  &lt;/span&gt;}&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  50:  &lt;/span&gt;&lt;span class="kwrd"&gt;catch&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  51:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  52:  &lt;/span&gt;strName = &lt;span class="str"&gt;&amp;quot;_AssemblyName&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  53:  &lt;/span&gt;strValue = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  54:  &lt;/span&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt;[] oArgs = { strName, &lt;span class="kwrd"&gt;false&lt;/span&gt;, MsoDocProperties.msoPropertyTypeString, strValue };&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  55:  &lt;/span&gt;typeDocCustomProps.InvokeMember(&lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;,&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  56:  &lt;/span&gt;BindingFlags.Default | BindingFlags.InvokeMethod, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  57:  &lt;/span&gt;oDocCustomProps, oArgs);&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  58:  &lt;/span&gt;}&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  59:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  60:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  61:  &lt;/span&gt;strName = &lt;span class="str"&gt;&amp;quot;_AssemblyLocation&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  62:  &lt;/span&gt;oDocAssemblyNameProp = typeDocCustomProps.InvokeMember(&lt;span class="str"&gt;&amp;quot;Item&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  63:  &lt;/span&gt;BindingFlags.Default | BindingFlags.GetProperty, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  64:  &lt;/span&gt;&lt;span class="kwrd"&gt;null&lt;/span&gt;, oDocCustomProps, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { strName });&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  65:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  66:  &lt;/span&gt;typeDocAssemblyNameProp = oDocAssemblyNameProp.GetType();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  67:  &lt;/span&gt;strValue = typeDocAssemblyNameProp.InvokeMember(&lt;span class="str"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  68:  &lt;/span&gt;BindingFlags.Default | BindingFlags.GetProperty, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  69:  &lt;/span&gt;oDocAssemblyNameProp, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { }).ToString();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  70:  &lt;/span&gt;}&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  71:  &lt;/span&gt;&lt;span class="kwrd"&gt;catch&lt;/span&gt;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  72:  &lt;/span&gt;{&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  73:  &lt;/span&gt;strName = &lt;span class="str"&gt;&amp;quot;_AssemblyLocation&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  74:  &lt;/span&gt;      strValue = &lt;span class="str"&gt;@&amp;quot;C:\WordDocument.application&amp;quot;&lt;/span&gt;; ;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  75:  &lt;/span&gt;      &lt;span class="kwrd"&gt;object&lt;/span&gt;[] oArgs = { strName, &lt;span class="kwrd"&gt;false&lt;/span&gt;, MsoDocProperties.msoPropertyTypeString, strValue };&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  76:  &lt;/span&gt;      typeDocCustomProps.InvokeMember(&lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  77:  &lt;/span&gt;      BindingFlags.Default | BindingFlags.InvokeMethod, &lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  78:  &lt;/span&gt;      &lt;span class="kwrd"&gt;null&lt;/span&gt;, oDocCustomProps, oArgs);&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  79:  &lt;/span&gt;}&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  80:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  81:  &lt;/span&gt;oDoc.Save();&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  82:  &lt;/span&gt;oDocBuiltInProps = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  83:  &lt;/span&gt;oDocCustomProps = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  84:  &lt;/span&gt;oDoc.Close(&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing,&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing);&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  85:  &lt;/span&gt;oDoc = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  86:  &lt;/span&gt;oWord.Quit(&lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; oMissing);&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  87:  &lt;/span&gt;oWord = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  88:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

          &lt;pre&gt;&lt;span class="lnum"&gt;  89:  &lt;/span&gt;}&lt;/pre&gt;
        &lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;Scroll to the top of the code window, and then add the following lines to the end of the list of using directives: 
        &lt;br /&gt;&lt;/li&gt;

      &lt;div class="csharpcode"&gt;
        &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.Office.Core;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Word = Microsoft.Office.Interop.Word;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Reflection;&lt;/pre&gt;
      &lt;/div&gt;
      &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

      &lt;li&gt;Press F5 to run the application.&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;&lt;b&gt;Note:- &lt;/b&gt; The &lt;b&gt;DocumentProperties&lt;/b&gt; and the &lt;b&gt;DocumentProperty&lt;/b&gt; interfaces are late bound interfaces. To use these interfaces, you must treat them like you would an &lt;b&gt;IDispatch&lt;/b&gt; interface.&lt;/p&gt;

    &lt;p&gt;For more details, please refer to: &lt;a href="NET%20http:/support.microsoft.com/kb/303296"&gt;How to Use Automation to Get and to Set Office Document Properties with Visual C#.&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;The next time the document is opened and saved, the Visual Studio Tools for Office runtime attaches the solution assembly to the document, and creates the Runtime Storage Control, if necessary. The Visual Studio Tools for Office runtime also sets the value of the &lt;b&gt;_AssemblyLocation&lt;/b&gt; custom document property to the GUID for the Runtime Storage Control.&lt;/p&gt;
    &lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;p&gt;&lt;/p&gt;

    &lt;ol&gt;
      &lt;p&gt;&lt;/p&gt;
    &lt;/ol&gt;

    &lt;p&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9809537" width="1" height="1"&gt;</content><author><name>Sidharth Shah</name><uri>http://blogs.msdn.com/members/Sidharth+Shah.aspx</uri></author></entry><entry><title>Presentation Close event is incorrectly fired while issuing Presentation Print Command</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/29/presentation-close-event-get-fired-on-powerpoint-presentation-print-command.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/29/presentation-close-event-get-fired-on-powerpoint-presentation-print-command.aspx</id><published>2009-06-30T06:42:00Z</published><updated>2009-06-30T06:42:00Z</updated><content type="html">&lt;p&gt;&lt;h&gt;&lt;strong&gt;&lt;font color="#1f497d"&gt;Summary&lt;/h&gt; &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;When the print command of a PowerPoint Presentation is issued, the presentation.close event is fired in addition to the Print event・&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;However, the expected behavior is that the presentation.close event should not get fired when the print command is issued. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#1f497d"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;&lt;strong&gt;Cause &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;&lt;strong&gt;       &lt;br /&gt;&lt;/strong&gt;This is a known issue with PowerPoint 2003/ 2007. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#1f497d"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;&lt;strong&gt;Resolution &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;&lt;strong&gt;&lt;/strong&gt;      &lt;br /&gt;Either of the solutions mentioned below can be used to work around this issue: &lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;   &lt;br /&gt;&lt;font color="#1f497d"&gt;&lt;strong&gt;Solution#1:&lt;/strong&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#1f497d"&gt;     &lt;br /&gt;This solution exploits the fact that there is a temporary presentation created for the purpose of background printing and temporary presentations are not added to the list of open presentations. &lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;   &lt;br /&gt;&lt;font color="#1f497d"&gt;So the workaround is to go through the list of presentations and if current presentation is not found there, then it is the temporary print presentation. The Close Event Handler would ignore the event in that case. &lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#0000ff"&gt;&lt;font color="#1f497d"&gt;The sample code (c#) to implement the workaround is given below:&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; applicationObject_PresentationPrint(Microsoft.Office.Interop.PowerPoint.PresentationPres)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{ &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    MessageBox.Show(&lt;span class="str"&gt;&amp;quot;applicationObject_PresentationPrint&amp;quot;&lt;/span&gt;); &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; applicationObject_PresentationClose(Microsoft.Office.Interop.PowerPoint.PresentationPres)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!IsPrintPres(Pres))&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="rem"&gt;//Write your code for presentation close event here. It will get executed only when a presentation is being closed.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        MessageBox.Show(&lt;span class="str"&gt;&amp;quot;applicationObject_PresentationClose&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsPrintPres(Microsoft.Office.Interop.PowerPoint.Presentation Pres)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Microsoft.Office.Interop.PowerPoint.Presentation p &lt;span class="kwrd"&gt;in&lt;/span&gt; applicationObject.Presentations)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (p == Pres)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p align="justify"&gt;&lt;font color="#004080"&gt;&lt;strong&gt;Solution#2:&lt;/strong&gt; &lt;/font&gt;&lt;/p&gt;
&lt;font color="#004080"&gt;
  &lt;p align="justify"&gt;
    &lt;br /&gt;Explicitly set the background print option to false (either programmatically or manually). The sample code(C#) to programmatically set the background print option to false is given below:&lt;/p&gt;

  &lt;div class="csharpcode"&gt;
    &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; applicationObject_AfterPresentationOpen(Microsoft.Office.Interop.PowerPoint.Presentation Pres)&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    MessageBox.Show(&lt;span class="str"&gt;&amp;quot;applicationObject_AfterPresentationOpen&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;}&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; applicationObject_AfterNewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation Pres)&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    MessageBox.Show(&lt;span class="str"&gt;&amp;quot;applicationObject_AfterNewPresentation&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;}&lt;/pre&gt;
  &lt;/div&gt;
  &lt;style type="text/css"&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9809005" width="1" height="1"&gt;</content><author><name>Shiv Khare</name><uri>http://blogs.msdn.com/members/Shiv+Khare.aspx</uri></author></entry><entry><title>How to Sign the SignatureLine using Office Open XML</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/19/how-to-sign-the-signatureline-using-office-open-xml.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/19/how-to-sign-the-signatureline-using-office-open-xml.aspx</id><published>2009-06-19T22:51:00Z</published><updated>2009-06-19T22:51:00Z</updated><content type="html">&lt;h4&gt;Introduction&lt;/h4&gt;  &lt;p&gt;We can use PackageDigitalSignatureManager class available in System.IO.Packaging namespace to sign any part of an Open XML document. However, when we try to sign a document that has a signature line using this class, we will notice that though the document appears as signed, the signature line still appears as “needs to be signed”. In order to have the signature appear in the signature line, we will need to do some additional tasks which are mentioned in the resolution section below. &lt;/p&gt;  &lt;h4&gt;Steps to Duplicate the Behaviour&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Create a new word document in Word 2007. &lt;/li&gt;    &lt;li&gt;Save this document to C:\Test\Test.docx. &lt;/li&gt;    &lt;li&gt;Insert a Signature Line by going to -&amp;gt; Insert tab-&amp;gt; in the Text group, point to the arrow next to Signature Line, and then click Microsoft Office Signature Line. &lt;/li&gt;    &lt;li&gt;Use the following code to sign the document     &lt;br /&gt;      &lt;br /&gt;      &lt;div class="csharpcode_abhatia"&gt;       &lt;pre&gt;&lt;span class="rem"&gt;// ========First function============&lt;/span&gt;
&lt;span class="rem"&gt;// Entry Point&lt;/span&gt;
&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DigiSign()
{
&lt;span class="rem"&gt;	// Open the Package    &lt;/span&gt;
&lt;span class="kwrd"&gt;	using&lt;/span&gt; (Package package = Package.Open(&amp;lt;&amp;lt; Word File Location &amp;gt;&amp;gt;))
	{
&lt;span class="rem"&gt;		// Get the certificate&lt;/span&gt;
		X509Certificate2 certificate = GetCertificate();
		SignAllParts(package, certificate);
	}
}
&lt;span class="rem"&gt;// ========End Of First function============&lt;/span&gt;

&lt;span class="rem"&gt;// ========Second function============&lt;/span&gt;

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SignAllParts(Package package, X509Certificate certificate)
{
&lt;span class="kwrd"&gt;	if&lt;/span&gt; (package == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;&amp;quot;SignAllParts(package)&amp;quot;&lt;/span&gt;);
	List&amp;lt;Uri&amp;gt; PartstobeSigned = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Uri&amp;gt;();
	List&amp;lt;PackageRelationshipSelector&amp;gt; SignableReleationships = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;PackageRelationshipSelector&amp;gt;();

&lt;span class="kwrd"&gt;	foreach&lt;/span&gt; (PackageRelationship relationship &lt;span class="kwrd"&gt;in&lt;/span&gt; package.GetRelationshipsByType(RT_OfficeDocument))
	{
&lt;span class="rem"&gt;		// Pass the releationship of the root. This is decided based on the RT_OfficeDocument &lt;/span&gt;
&lt;span class="rem"&gt;		// &lt;a href="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"&gt;http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument&lt;/a&gt;&lt;/span&gt;
		CreateListOfSignableItems(relationship, PartstobeSigned, SignableReleationships);
	}
&lt;span class="rem"&gt;	// Create the DigitalSignature Manager&lt;/span&gt;
	PackageDigitalSignatureManager dsm = &lt;span class="kwrd"&gt;new&lt;/span&gt; PackageDigitalSignatureManager(package);
	dsm.CertificateOption =  CertificateEmbeddingOption.InSignaturePart;         
&lt;span class="kwrd"&gt;	try&lt;/span&gt;
	{
		dsm.Sign(PartstobeSigned, certificate, SignableReleationships);
	}
&lt;span class="kwrd"&gt;	catch&lt;/span&gt; (CryptographicException ex)
	{
		MessageBox.Show(ex.InnerException.ToString());
	}

}&lt;span class="rem"&gt;// end:SignAllParts()&lt;/span&gt;
&lt;span class="rem"&gt;// ========End of Second function============&lt;/span&gt;

&lt;span class="rem"&gt;// ========Third function============&lt;/span&gt;

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateListOfSignableItems(PackageRelationship relationship, List&amp;lt;Uri&amp;gt; PartstobeSigned, List&amp;lt;PackageRelationshipSelector&amp;gt; SignableReleationships)
{
&lt;span class="rem"&gt;	// This function adds the releation to SignableReleationships. And then it gets the part based on the releationship. Parts URI gets added to the PartstobeSigned list.&lt;/span&gt;
	PackageRelationshipSelector selector = &lt;span class="kwrd"&gt;new&lt;/span&gt; PackageRelationshipSelector(relationship.SourceUri, PackageRelationshipSelectorType.Id, relationship.Id);
	SignableReleationships.Add(selector);
&lt;span class="kwrd"&gt;	if&lt;/span&gt; (relationship.TargetMode == TargetMode.Internal)
	{
		PackagePart part = relationship.Package.GetPart(PackUriHelper.ResolvePartUri(relationship.SourceUri, relationship.TargetUri));
&lt;span class="kwrd"&gt;		if&lt;/span&gt; (PartstobeSigned.Contains(part.Uri) == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
		{
			PartstobeSigned.Add(part.Uri);
&lt;span class="rem"&gt;			// GetRelationships Function: Returns a Collection Of all the releationships that are owned by the part.&lt;/span&gt;
&lt;span class="kwrd"&gt;			foreach&lt;/span&gt; (PackageRelationship childRelationship &lt;span class="kwrd"&gt;in&lt;/span&gt; part.GetRelationships())
			{
				CreateListOfSignableItems(childRelationship, PartstobeSigned, SignableReleationships);
			}
		}
	}
}
&lt;span class="rem"&gt;// ========End of Third function============&lt;/span&gt;

&lt;span class="rem"&gt;// ======== Fourth function============&lt;/span&gt;
&lt;span class="kwrd"&gt;static&lt;/span&gt; X509Certificate2 GetCertificate()
{
	X509Store certStore = &lt;span class="kwrd"&gt;new&lt;/span&gt; X509Store(StoreLocation.CurrentUser);
	certStore.Open(OpenFlags.ReadOnly);
	X509Certificate2Collection certs =X509Certificate2UI.SelectFromCollection(certStore.Certificates,&lt;span class="str"&gt;&amp;quot;Select a certificate&amp;quot;&lt;/span&gt;,&lt;span class="str"&gt;&amp;quot;Please select a certificate&amp;quot;&lt;/span&gt;,
	X509SelectionFlag.SingleSelection);
&lt;span class="kwrd"&gt;	return&lt;/span&gt; certs.Count &amp;gt; 0 ? certs[0] : &lt;span class="kwrd"&gt;null&lt;/span&gt;;
}
&lt;span class="rem"&gt;// ========End of Fourth function============&lt;/span&gt;&lt;/pre&gt;
    &lt;/div&gt;

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;Open the document, you will notice that the doc is signed but signature line still shows as “needs to be signed”. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Resolution &lt;/h4&gt;

&lt;p&gt;The point is, Sign method expects an XML file of ContentType “System.Security.Cryptography.Xml.DataObject” which should include the GUID of the signatureLine needs to be signed. &lt;/p&gt;

&lt;p&gt;Note: Whenever we create a SignatureLine, it gets an unique GUID which we need to use while signing the SignatureLine. &lt;/p&gt;

&lt;p&gt;The structure of the XML file should be &lt;/p&gt;

&lt;div class="htmlcode"&gt;
  &lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SignatureProperties&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.w3.org/2000/09/xmldsig#&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SignatureProperty&lt;/span&gt; &lt;span class="attr"&gt;Id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;idOfficeV1Details&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;#idPackageSignature&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SignatureInfoV1&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/office/2006/digsig&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SetupID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;{3CF6B91E-C5F6-46A4-B036-72597274FCC0}&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SetupID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SignatureText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Test User&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SignatureText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ManifestHashAlgorithm&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2000/09/xmldsig#sha1&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ManifestHashAlgorithm&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SignatureInfoV1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SignatureProperty&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SignatureProperties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Where SetupID&amp;#160; represents the GUID of the SignatureLine. &lt;/p&gt;

&lt;p&gt;Once the XML file is created, we can call the Sign method available in PackageDigitalSignatureManager class. Following is the complete listing of the class: &lt;/p&gt;

&lt;div class="csharpcode_abhatia"&gt;
  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Drawing;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Forms;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO.Packaging;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Cryptography;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Cryptography.X509Certificates;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Cryptography.Xml;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Xml;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; DigitalSign
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SignDoc
    {
        &lt;span class="rem"&gt;// Get help about them from http://download.microsoft.com/download/2/4/8/24862317-78F0-4C4B-B355-C7B2C1D997DB/%5BMS-OFFCRYPTO%5D.pdf&lt;/span&gt;

        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; RT_OfficeDocument = &lt;span class="str"&gt;&amp;quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; OfficeObjectID = &lt;span class="str"&gt;&amp;quot;idOfficeObject&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SignatureID = &lt;span class="str"&gt;&amp;quot;idPackageSignature&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ManifestHashAlgorithm = &lt;span class="str"&gt;&amp;quot;http://www.w3.org/2000/09/xmldsig#sha1&amp;quot;&lt;/span&gt;;
        
       &lt;span class="rem"&gt;// Entry Point&lt;/span&gt;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DigiSign()
        {
        &lt;span class="rem"&gt;// Open the Package    &lt;/span&gt;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; (Package package = Package.Open(&amp;lt;&amp;lt; Word File&amp;gt;&amp;gt;)
            {
                &lt;span class="rem"&gt;// Get the certificate&lt;/span&gt;
                X509Certificate2 certificate = GetCertificate();
                SignAllParts(package, certificate);
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SignAllParts(Package package, X509Certificate certificate)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (package == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;&amp;quot;SignAllParts(package)&amp;quot;&lt;/span&gt;);
            List&amp;lt;Uri&amp;gt; PartstobeSigned = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Uri&amp;gt;();
            List&amp;lt;PackageRelationshipSelector&amp;gt; SignableReleationships = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;PackageRelationshipSelector&amp;gt;();

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (PackageRelationship relationship &lt;span class="kwrd"&gt;in&lt;/span&gt; package.GetRelationshipsByType(RT_OfficeDocument))
            {
                &lt;span class="rem"&gt;// Pass the releationship of the root. This is decided based on the RT_OfficeDocument (http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument)&lt;/span&gt;
                CreateListOfSignableItems(relationship, PartstobeSigned, SignableReleationships);
            }
            &lt;span class="rem"&gt;// Create the DigitalSignature Manager&lt;/span&gt;
            PackageDigitalSignatureManager dsm = &lt;span class="kwrd"&gt;new&lt;/span&gt; PackageDigitalSignatureManager(package);
            dsm.CertificateOption =  CertificateEmbeddingOption.InSignaturePart;
           
            &lt;span class="kwrd"&gt;string&lt;/span&gt; signatureID = SignatureID;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; manifestHashAlgorithm = ManifestHashAlgorithm;
            System.Security.Cryptography.Xml.DataObject officeObject = CreateOfficeObject(signatureID, manifestHashAlgorithm);
            Reference officeObjectReference = &lt;span class="kwrd"&gt;new&lt;/span&gt; Reference(&lt;span class="str"&gt;&amp;quot;#&amp;quot;&lt;/span&gt; + OfficeObjectID);

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
              dsm.Sign(PartstobeSigned, certificate, SignableReleationships, signatureID, &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Security.Cryptography.Xml.DataObject[] { officeObject }, &lt;span class="kwrd"&gt;new&lt;/span&gt; Reference[] { officeObjectReference }); 
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (CryptographicException ex)
            {
                MessageBox.Show(ex.InnerException.ToString());
            }

        }&lt;span class="rem"&gt;// end:SignAllParts()&lt;/span&gt;

        &lt;span class="rem"&gt;/**************************SignDocument******************************/&lt;/span&gt;
        &lt;span class="rem"&gt;//  This function is a helper function. The main role of this function is to &lt;/span&gt;
        &lt;span class="rem"&gt;//  create two lists, one with Package Parts that you want to sign, the other &lt;/span&gt;
        &lt;span class="rem"&gt;//  containing PacakgeRelationshipSelector objects which indicate relationships to sign.&lt;/span&gt;
        &lt;span class="rem"&gt;/*******************************************************************/&lt;/span&gt;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateListOfSignableItems(PackageRelationship relationship, List&amp;lt;Uri&amp;gt; PartstobeSigned, List&amp;lt;PackageRelationshipSelector&amp;gt; SignableReleationships)
        {
            &lt;span class="rem"&gt;// This function adds the releation to SignableReleationships. And then it gets the part based on the releationship. Parts URI gets added to the PartstobeSigned list.&lt;/span&gt;
            PackageRelationshipSelector selector = &lt;span class="kwrd"&gt;new&lt;/span&gt; PackageRelationshipSelector(relationship.SourceUri, PackageRelationshipSelectorType.Id, relationship.Id);
            SignableReleationships.Add(selector);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (relationship.TargetMode == TargetMode.Internal)
            {
                PackagePart part = relationship.Package.GetPart(PackUriHelper.ResolvePartUri(relationship.SourceUri, relationship.TargetUri));
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (PartstobeSigned.Contains(part.Uri) == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
                {
                    PartstobeSigned.Add(part.Uri);
                &lt;span class="rem"&gt;// GetRelationships Function: Returns a Collection Of all the releationships that are owned by the part.&lt;/span&gt;
                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (PackageRelationship childRelationship &lt;span class="kwrd"&gt;in&lt;/span&gt; part.GetRelationships())
                    {
                        CreateListOfSignableItems(childRelationship, PartstobeSigned, SignableReleationships);
                    }
                }
            }
        }
            &lt;span class="rem"&gt;/**************************SignDocument******************************/&lt;/span&gt;
        &lt;span class="rem"&gt;//  Once you create the list and try to sign it, Office will not validate the Signature.&lt;/span&gt;
        &lt;span class="rem"&gt;//  To allow Office to validate the signature, it requires a custom object which should be added to the &lt;/span&gt;
        &lt;span class="rem"&gt;//  signature parts. This function loads the OfficeObject.xml resource.&lt;/span&gt;
        &lt;span class="rem"&gt;//  Please note that GUID being passed in document.Loadxml. &lt;/span&gt;
        &lt;span class="rem"&gt;//  Background Information: Once you add a SignatureLine in Word, Word gives a unique GUID to it. Now while loading the&lt;/span&gt;
        &lt;span class="rem"&gt;//  OfficeObject.xml, we need to make sure that The this GUID should match to the ID of the signature line. &lt;/span&gt;
        &lt;span class="rem"&gt;//  So if you are generating a SignatureLine programmtically, then mmake sure that you generate the GUID for the &lt;/span&gt;
        &lt;span class="rem"&gt;//  SignatureLine and for this element. &lt;/span&gt;
        &lt;span class="rem"&gt;/*******************************************************************/&lt;/span&gt;

        &lt;span class="kwrd"&gt;static&lt;/span&gt; System.Security.Cryptography.Xml.DataObject CreateOfficeObject(
           &lt;span class="kwrd"&gt;string&lt;/span&gt; signatureID, &lt;span class="kwrd"&gt;string&lt;/span&gt; manifestHashAlgorithm)
        {
            XmlDocument document = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlDocument();
            document.LoadXml(String.Format(Properties.Resources.OfficeObject, signatureID, manifestHashAlgorithm, &lt;span class="str"&gt;&amp;quot;{3CF6B91E-C5F6-46A4-B036-72597274FCC0}&amp;quot;&lt;/span&gt;));
            System.Security.Cryptography.Xml.DataObject officeObject = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Security.Cryptography.Xml.DataObject();
            &lt;span class="rem"&gt;// do not change the order of the following two lines&lt;/span&gt;
            officeObject.LoadXml(document.DocumentElement); &lt;span class="rem"&gt;// resets ID&lt;/span&gt;
            officeObject.Id = OfficeObjectID; &lt;span class="rem"&gt;// required ID, do not change&lt;/span&gt;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; officeObject;
        }
        &lt;span class="rem"&gt;/********************************************************/&lt;/span&gt;

        &lt;span class="kwrd"&gt;static&lt;/span&gt; X509Certificate2 GetCertificate()
        {
            X509Store certStore = &lt;span class="kwrd"&gt;new&lt;/span&gt; X509Store(StoreLocation.CurrentUser);
            certStore.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certs =X509Certificate2UI.SelectFromCollection(certStore.Certificates,&lt;span class="str"&gt;&amp;quot;Select a certificate&amp;quot;&lt;/span&gt;,&lt;span class="str"&gt;&amp;quot;Please select a certificate&amp;quot;&lt;/span&gt;,
                    X509SelectionFlag.SingleSelection);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; certs.Count &amp;gt; 0 ? certs[0] : &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; button2_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            DialogResult a = openFileDialog1.ShowDialog();
            openFileDialog1.InitialDirectory = &lt;span class="str"&gt;&amp;quot;C:\\test&amp;quot;&lt;/span&gt;;
            textBox1.Text=openFileDialog1.FileName;
        }
  
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Please note that you need to change the GUID of the signatureLine used in the above sample. Following section shows you to how to get this information for an existing SignatureLine. &lt;/p&gt;

&lt;h4&gt;How to Check GUID of the SignatureLine &lt;/h4&gt;

&lt;p&gt;In order to know the GUID of the signatureLine which you have inserted using Word: &lt;/p&gt;

&lt;ol type="A"&gt;
  &lt;li&gt;Extract the content of the package. &lt;/li&gt;

  &lt;li&gt;Go to SignatureLine declaration of &lt;em&gt;document.xml&lt;/em&gt;. You will see a declaration like: 

    &lt;br /&gt;

    &lt;br /&gt;

    &lt;div class="htmlcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;o:signatureline&lt;/span&gt; &lt;span class="attr"&gt;v:ext&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;edit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{3CF6B91E-C5F6-46A4-B036-72597274FCC0}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;provid&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{00000000-0000-0000-0000-000000000000}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;o:suggestedsigner&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;a&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;o:suggestedsigner2&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;a&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;o:suggestedsigneremail&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;a&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;issignatureline&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;

    &lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Where id attribute stands for the GUID. This GUID needs to be passed in the XML file while signing. &lt;/p&gt;

&lt;h4&gt;Reference for XML generation&lt;/h4&gt;

&lt;p&gt;&lt;a href="http://download.microsoft.com/download/2/4/8/24862317-78F0-4C4B-B355-C7B2C1D997DB/%5BMS-OFFCRYPTO%5D.pdf" mce_href="http://download.microsoft.com/download/2/4/8/24862317-78F0-4C4B-B355-C7B2C1D997DB/%5BMS-OFFCRYPTO%5D.pdf"&gt;http://download.microsoft.com/download/2/4/8/24862317-78F0-4C4B-B355-C7B2C1D997DB/%5BMS-OFFCRYPTO%5D.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;
&lt;style type="text/css"&gt;

.csharpcode_abhatia
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
	width: inherit;
	height: 400px;
	overflow:auto;
	/*overflow-x: auto;*/
}
.csharpcode_abhatia pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode_abhatia pre { margin: 0em; }
.csharpcode_abhatia .rem { color: #008000; }
.csharpcode_abhatia .kwrd { color: #0000ff; }
.csharpcode_abhatia .str { color: #ff0000; }
.csharpcode_abhatia .op { color: #0000c0; }
.csharpcode_abhatia .preproc { color: #cc6633; }
.csharpcode_abhatia .asp { background-color: #ffff00; }
.csharpcode_abhatia .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode_abhatia .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode_abhatia .lnum { color: #606060; }

.htmlcode
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	/*white-space: pre;*/
	width: inherit;
	overflow:auto;
}

.htmlcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	/*background-color: #ffffff;*/
	/*white-space: pre;*/
}

.htmlcode .html { color: #800000; }
.htmlcode .attr { color: #ff0000; }
.htmlcode .str { color: #ff0000; }&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9791985" width="1" height="1"&gt;</content><author><name>Ankush Bhatia</name><uri>http://blogs.msdn.com/members/Ankush+Bhatia.aspx</uri></author></entry><entry><title>MapPoint does not appear in the list of products while creating shared add-in in Visual Studio 2008</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/18/mappoint-does-not-appear-in-the-list-of-products-while-creating-shared-add-in-in-visual-studio-2008.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/18/mappoint-does-not-appear-in-the-list-of-products-while-creating-shared-add-in-in-visual-studio-2008.aspx</id><published>2009-06-18T22:02:00Z</published><updated>2009-06-18T22:02:00Z</updated><content type="html">&lt;P&gt;&lt;B&gt;Issue Description: &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;On a machine having Visual Studio 2008 and MapPoint 2009 installed, MapPoint does not appear in the list of products while developing a shared add-in using Visual Studio 2008, as shown below:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/MapPointdoesnotappearinthelistofproducts_4B1B/Untitled1.png" mce_href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/MapPointdoesnotappearinthelistofproducts_4B1B/Untitled1.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; MARGIN-LEFT: 0px; BORDER-TOP: 0px; MARGIN-RIGHT: 0px; BORDER-RIGHT: 0px" title=Untitled1 border=0 alt=Untitled1 src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/MapPointdoesnotappearinthelistofproducts_4B1B/Untitled1_thumb.png" width=517 height=401 mce_src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/MapPointdoesnotappearinthelistofproducts_4B1B/Untitled1_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This is a bug in MapPoint 2009.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Workaround for this issue is to create necessary registry entries. &lt;/P&gt;
&lt;P&gt;Follow the steps below to resolve this issue:&lt;/P&gt;
&lt;P&gt;1) Create a blank text document and rename it to have ".reg" extension.&lt;/P&gt;
&lt;P&gt;2) Copy &amp;amp; paste the following to the ".reg" file created in step 1.&lt;/P&gt;
&lt;P&gt;Windows Registry Editor Version 5.00&lt;/P&gt;
&lt;P&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\AddinWizard7.1c\Microsoft MapPoint]&lt;/P&gt;
&lt;P&gt;"DisplayAdvFeatures"=dword:00000000&lt;/P&gt;
&lt;P&gt;"RegistryRoot"="Software\\Microsoft\\MapPoint\\Addins"&lt;/P&gt;
&lt;P&gt;"StartupFlag"=dword:00000003&lt;/P&gt;
&lt;P&gt;3) Save &amp;amp; close the document.&lt;/P&gt;
&lt;P&gt;4) Double click the ".reg" file(alternatively, ".reg" file can also be imported in windows registry)&lt;/P&gt;
&lt;P&gt;Now, MapPoint should appear in the list of products in the shared add-in wizard in Visual studio 2008.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9777089" width="1" height="1"&gt;</content><author><name>Ajay Bandooni</name><uri>http://blogs.msdn.com/members/Ajay+Bandooni.aspx</uri></author><category term="AddIns" scheme="http://blogs.msdn.com/vsod/archive/tags/AddIns/default.aspx" /><category term="Automation" scheme="http://blogs.msdn.com/vsod/archive/tags/Automation/default.aspx" /><category term="Mappoint" scheme="http://blogs.msdn.com/vsod/archive/tags/Mappoint/default.aspx" /><category term="COM addin" scheme="http://blogs.msdn.com/vsod/archive/tags/COM+addin/default.aspx" /><category term="Shared addin" scheme="http://blogs.msdn.com/vsod/archive/tags/Shared+addin/default.aspx" /></entry><entry><title>Creating charts in Word and PowerPoint using newly introduced Object Model in Office 2007 Service Pack 2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/15/creating-charts-in-word-and-powerpoint-using-newly-introduced-object-model-in-office-2007-service-pack-2.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/15/creating-charts-in-word-and-powerpoint-using-newly-introduced-object-model-in-office-2007-service-pack-2.aspx</id><published>2009-06-16T00:34:00Z</published><updated>2009-06-16T00:34:00Z</updated><content type="html">&lt;P&gt;Office 2007 SP2 has added a major inclusion to the Object Models of Word and PowerPoint, i.e., Object Model for Charts. This new object model (OM) provides office application programmers flexibility to manipulate charts programmatically in Word and PowerPoint.&lt;/P&gt;
&lt;P&gt;The new OM in Word and PowerPoint is similar to the one that existed for Excel prior to Office SP2. Chart objects can be accessed using the &lt;I&gt;Shape.Chart&lt;/I&gt; property. Every &lt;I&gt;Chart&lt;/I&gt; object contains a &lt;I&gt;ChartData&lt;/I&gt; property which refers to the Excel worksheet which holds the data for the chart. Once you get hold of the worksheet which holds a chart’s data, you can use Excel’s object model to manipulate that data.&lt;/P&gt;
&lt;P&gt;In this post, we will try to add charts to Word document using this newly added object model. But, before we dive into the coding part, make sure that Service Pack 2 for Microsoft Office 2007 is installed on your machine. Also, I will be using Visual Studio 2008; however, the steps mentioned here should also work for Visual Studio 2005. In case you face any difficulty, feel free to ask me.&lt;/P&gt;
&lt;P&gt;First of all create a new Windows Forms application in your favorite .Net programming language (i.e. C# or VB.Net). Add a new button to the form, and double click it to add the code in the &lt;I&gt;Click&lt;/I&gt; event handler’s for it. &lt;/P&gt;
&lt;P&gt;Next step is to add references to the required assemblies for enabling .Net code automate Word and PowerPoint. For this, right click on the &lt;I&gt;References&lt;/I&gt; folder in your Solution Explorer (if you have created a VB.Net project, you may have to click &lt;I&gt;Show All Files &lt;/I&gt;for making the References folder visible). Now select the COM tab in the &lt;I&gt;Add reference&lt;/I&gt; dialog box that got opened, and search for following entries:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Microsoft Excel 12.0 Object Library &lt;/LI&gt;
&lt;LI&gt;Microsoft PowerPoint 12.0 Object Library &lt;/LI&gt;
&lt;LI&gt;Microsoft Word 12.0 Object Library &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Now, you’ll be asking why we need to select these entries from the COM tab rather than the .Net tab, as we have the Primary Interop Assemblies installed on our machines, and why in the world, do we need Excel object library for? &lt;/P&gt;
&lt;P&gt;Well for your first question, as you know Visual Studio 2008 uses its own set of Office Primary Interop Assemblies (PIAs) when you compile and link your projects and not the ones that are installed in your system’s Global Assembly Cache (GAC), selecting assemblies from the COM tab (rather than the .Net tab) ensures that Visual studio will not compile/link your project with its own set of PIAs, but will generate ones from the corresponding COM type libraries. If we do not follow this step, Visual Studio will try to link our code with its own copy of PIAs, which do not contain declarations of the new Office SP2 object model.&lt;/P&gt;
&lt;P&gt;And, for your second question, the Chart object model in SP2 has added a new property to the Chart object called &lt;I&gt;ChartData,&lt;/I&gt; which (as you might have guessed) represents the data of a chart. This &lt;I&gt;ChartData&lt;/I&gt; has a property named &lt;I&gt;Workbook&lt;/I&gt; which corresponds to the Excel Workbook containing the data of your chart. Therefore, we need the Excel object library to be able to interact with this workbook programmatically.&lt;/P&gt;
&lt;P&gt;Now, let’s first write the code require to insert a chart, set its data, and set some of its visible properties. We will discuss about the new classes/properties of the new object model later.&lt;/P&gt;
&lt;P&gt;Below is an example, which shows how to insert a chart to a Word document, accesses chart’s underlying data’s workbook, modify that data and finally sets some of its other properties. (Line numbers mentioned are just for indicative purpose.)&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;Word.Application word = &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;word = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Word.Application();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;word.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;Word.Document doc = word.Documents.Add(&lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing, &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing, &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing, &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;Word.Chart wdChart = doc.InlineShapes.AddChart(Microsoft.Office.Core.XlChartType.xl3DColumn , &lt;SPAN class=kwrd&gt;ref&lt;/SPAN&gt; missing).Chart;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;Word.ChartData chartData = wdChart.ChartData;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;Excel.Workbook dataWorkbook = (Excel.Workbook)chartData.Workbook;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;Excel.Worksheet dataSheet = (Excel.Worksheet)dataWorkbook.Worksheets[1];&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;Excel.Range tRange = dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"A1"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"B5"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;Excel.ListObject tbl1 = dataSheet.ListObjects[&lt;SPAN class=str&gt;"Table1"&lt;/SPAN&gt;];&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;tbl1.Resize(tRange);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"A2"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"Bikes"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"A3"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"Accessories"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"A4"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"Repairs"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"A5"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"Clothing"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"B2"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"1000"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  17:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"B3"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"2500"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"B4"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"4000"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  19:  &lt;/SPAN&gt;((Excel.Range)dataSheet.Cells.get_Range(&lt;SPAN class=str&gt;"B5"&lt;/SPAN&gt;, missing)).FormulaR1C1 = &lt;SPAN class=str&gt;"3000"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  20:  &lt;/SPAN&gt;wdChart.ChartTitle.Font.Italic = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  21:  &lt;/SPAN&gt;wdChart.ChartTitle.Font.Size = 18;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  22:  &lt;/SPAN&gt;wdChart.ChartTitle.Font.Color = Color.Black.ToArgb();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  23:  &lt;/SPAN&gt;wdChart.ChartTitle.Text = &lt;SPAN class=str&gt;"2007 Sales"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  24:  &lt;/SPAN&gt;wdChart.ChartTitle.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  25:  &lt;/SPAN&gt;wdChart.ChartTitle.Format.Line.ForeColor.RGB = Color.Black.ToArgb();&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  26:  &lt;/SPAN&gt;wdChart.ApplyDataLabels(Word.XlDataLabelsType.xlDataLabelsShowLabel, missing, missing, missing, missing, missing, missing, missing, missing, missing);&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  27:  &lt;/SPAN&gt;dataWorkbook.Application.Quit();&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;








.csharpcode
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
	width: inherit;
	overflow-x: auto;
	overflow-y: none;
}
.csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #ff0000; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;As you might have guessed, the main class here is the &lt;I&gt;Chart&lt;/I&gt; class. We can get an object of Chart class by accessing the &lt;I&gt;Shape.Chart&lt;/I&gt; property. The call to &lt;I&gt;Document.InlineShapes.AddChart()&lt;/I&gt; method returns a Shape object and we have accessed its &lt;I&gt;Chart&lt;/I&gt; object in line no 5. &lt;/P&gt;
&lt;P&gt;The next object in question is the &lt;I&gt;ChartData&lt;/I&gt; object. We require this object to access the underlying workbook containing all the data of our chart, and we have accessed it using &lt;I&gt;ChartData.Workbook&lt;/I&gt; property. &lt;/P&gt;
&lt;P&gt;After getting the Workbook object of the &lt;I&gt;ChartData&lt;/I&gt;, the next task is just using object model of Excel to insert/update data in its cells (lines 12 to 19). &lt;/P&gt;
&lt;P&gt;Once we are finished with filling the data in the Excel workbook, we set some of the visible properties of chart like, Font, Text and Style of its Title; enable display of labels on the Chart (which are the bars in our example). After doing all this, the last task is to quit the Excel application (which automatically got created when we accessed the &lt;I&gt;ChartData.Workbook&lt;/I&gt; object). &lt;/P&gt;
&lt;P&gt;Here is how the final chart looks like after running the above code: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/CreatingchartsinWordandPowerPointusingne_2739/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/CreatingchartsinWordandPowerPointusingne_2739/image_2.png"&gt;&lt;IMG style="DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; MARGIN-RIGHT: auto" title="Chart Sample" alt="Chart Sample" src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/CreatingchartsinWordandPowerPointusingne_2739/image_thumb.png" width=524 height=304 mce_src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/CreatingchartsinWordandPowerPointusingne_2739/image_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9756031" width="1" height="1"&gt;</content><author><name>manvir.singh</name><uri>http://blogs.msdn.com/members/manvir.singh.aspx</uri></author><category term="Automation" scheme="http://blogs.msdn.com/vsod/archive/tags/Automation/default.aspx" /><category term="Word" scheme="http://blogs.msdn.com/vsod/archive/tags/Word/default.aspx" /><category term="Office" scheme="http://blogs.msdn.com/vsod/archive/tags/Office/default.aspx" /><category term="PowerPoint" scheme="http://blogs.msdn.com/vsod/archive/tags/PowerPoint/default.aspx" /><category term="Charts" scheme="http://blogs.msdn.com/vsod/archive/tags/Charts/default.aspx" /><category term="SP2" scheme="http://blogs.msdn.com/vsod/archive/tags/SP2/default.aspx" /></entry><entry><title>Visual Basic 6 Controls stop working after Security Advisory 960715</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/06/05/visual-basic-6-controls-stop-working-after-security-advisory-960715.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/06/05/visual-basic-6-controls-stop-working-after-security-advisory-960715.aspx</id><published>2009-06-05T04:57:00Z</published><updated>2009-06-05T04:57:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;Summary of the issue:&lt;/STRONG&gt; After installing security advisory &lt;A href="http://www.microsoft.com/technet/security/advisory/960715.mspx" mce_href="http://www.microsoft.com/technet/security/advisory/960715.mspx"&gt;960715&lt;/A&gt; and opening a workbook with one of Visual Basic 6 ActiveX controls embedded in the workbook you receive an error:&lt;/P&gt;
&lt;P&gt;“Object library invalid or contains references to object definitions that could not be found” or “Element not found.”&lt;/P&gt;
&lt;P&gt;See Microsoft security bulletin MS08-070 article 932349 for more information regarding this error:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.microsoft.com/kb/932349" mce_href="http://support.microsoft.com/kb/932349"&gt;MS08-070: Vulnerabilities in Visual Basic 6.0 Runtime Extended Files (ActiveX Controls) could allow remote code execution&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;Please refer to the “Known issues with this security update” in the “More Information” section.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Cause:&lt;/STRONG&gt; The security advisory listed above sets the kill bit for the following Visual Basic 6 ActiveX controls.&lt;/P&gt;
&lt;P&gt;The VB6 controls affected are:&lt;/P&gt;
&lt;TABLE style="BORDER-COLLAPSE: collapse" border=1 cellSpacing=0 cellPadding=0 width="100%"&gt;
&lt;COLGROUP&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD height=20&gt;&lt;STRONG&gt;File Name&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Control Name&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Class Identifier (CLSID)&lt;/STRONG&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Comct232.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;Windows Common Controls&lt;/TD&gt;
&lt;TD&gt;{1E216240-1B7D-11CF-9D53-00AA003C9CB6}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Mschrt20.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;Chart Control (OLEDB)&lt;/TD&gt;
&lt;TD&gt;{3A2B370C-BA0A-11d1-B137-0000F8753F5D}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Mscomct2.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;Windows Common Controls-2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;{B09DE715-87C1-11d1-8BE3-0000F8754DA1}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Msdatgrd.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;DataGrid Control 6.0 (OLEDB)&lt;/TD&gt;
&lt;TD&gt;{cde57a43-8b86-11d0-b3c6-00a0c90aea82}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Msflxgrd.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;FlexGrid Control 6.0&lt;/TD&gt;
&lt;TD&gt;{6262d3a0-531b-11cf-91f6-c2863c385e30}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Mshflxgd.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;Hierarchical FlexGrid Control&lt;/TD&gt;
&lt;TD&gt;{0ECD9B64-23AA-11d0-B351-00A0C9055D8E}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;Msmask32.ocx&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;Masked Edit Control&lt;/TD&gt;
&lt;TD&gt;{C932BA85-4374-101B-A56C-00AA003668DC}&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt" height=20&gt;
&lt;TD style="HEIGHT: 15pt" height=20&gt;MSWinsck.ocx&lt;/TD&gt;
&lt;TD&gt;Winsock Control 6.0&lt;/TD&gt;
&lt;TD&gt;{248dd896-bb45-11cf-9abc-0080c7e7b78d}&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Theses kill bits were necessary because of security vulnerabilities found within these controls and addressed in Microsoft security bulletin MS08-070 &lt;A href="http://www.microsoft.com/technet/security/Bulletin/ms08-070.mspx" mce_href="http://www.microsoft.com/technet/security/Bulletin/ms08-070.mspx"&gt;http://www.microsoft.com/technet/security/Bulletin/ms08-070.mspx&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To ensure that the correct ActiveX control is being used Microsoft had disabled the particular GUID or “kill bit” the control. Setting the kill bit makes sure that even if a vulnerable component (i.e. malicious code) is introduced or is re-introduced to a system, it remains inert and harmless. Kill-Bits must be issued to prevent old / vulnerable signed versions of controls from being effectively imposed on users. Even if you have a fixed version of the control on your system, a renamed and signed DLL or OCX served from a malicious web page can revert the machine to an insecure state. The software vendor cannot just update the control with the same GUID because there is no way ensure that control in use is the updated control. &lt;/P&gt;
&lt;P&gt;For more information about the kill bit for ActiveX controls, see the following Microsoft Security Vulnerability Research &amp;amp; Defense Blog posts: &lt;/P&gt;
&lt;P&gt;The Kill-Bit FAQ: Part 1 of 3 &lt;BR&gt;&lt;A href="http://blogs.technet.com/swi/archive/2008/02/06/The-Kill_2D00_Bit-FAQ_3A00_-Part-1-of-3.aspx" mce_href="http://blogs.technet.com/swi/archive/2008/02/06/The-Kill_2D00_Bit-FAQ_3A00_-Part-1-of-3.aspx"&gt;http://blogs.technet.com/swi/archive/2008/02/06/The-Kill_2D00_Bit-FAQ_3A00_-Part-1-of-3.aspx&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The Kill-Bit FAQ: Part 2 of 3 &lt;BR&gt;&lt;A href="http://blogs.technet.com/swi/archive/2008/02/07/The-Kill_2D00_Bit-FAQ_3A00_-Post-2-of-3.aspx" mce_href="http://blogs.technet.com/swi/archive/2008/02/07/The-Kill_2D00_Bit-FAQ_3A00_-Post-2-of-3.aspx"&gt;http://blogs.technet.com/swi/archive/2008/02/07/The-Kill_2D00_Bit-FAQ_3A00_-Post-2-of-3.aspx&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The Kill-Bit FAQ: Part 3 of 3 &lt;BR&gt;&lt;A href="http://blogs.technet.com/swi/archive/2008/02/08/The-Kill_2D00_Bit-FAQ_3A00_-Part-3-of-3.aspx" mce_href="http://blogs.technet.com/swi/archive/2008/02/08/The-Kill_2D00_Bit-FAQ_3A00_-Part-3-of-3.aspx"&gt;http://blogs.technet.com/swi/archive/2008/02/08/The-Kill_2D00_Bit-FAQ_3A00_-Part-3-of-3.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;To resolve this issue you must update the development computer with updated controls and then update the controls on the client computer. Please see step by step instructions below.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;On Development Computer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. Install the Microsoft Visual Basic 6.0 Service Pack 6 Cumulative Update &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cb824e35-0403-45c4-9e41-459f0eb89e36" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cb824e35-0403-45c4-9e41-459f0eb89e36"&gt;http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cb824e35-0403-45c4-9e41-459f0eb89e36&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. Delete the cached versions of the control type libraries (extender files). To do this, search your hard drive for ".exd," and delete all the .exd files. The .exd files will be re-created automatically using the new controls the next time that you use VBA. The extender files will reside under the users profile and may reside in multiple locations such as:&lt;/P&gt;
&lt;P&gt;C:\documents and settings\username\Application Data\Microsoft\Forms&lt;/P&gt;
&lt;P&gt;C:\documents and settings\username\AppData\Local\Temp\VBE&lt;/P&gt;
&lt;P&gt;Note that you can search the "HKEY_CLASSES_ROOT\TypeLib" key in the registry using the search term "exd" to find the locations where the extender files reside. &lt;/P&gt;
&lt;P&gt;3. Open the Excel workbook with the ActiveX control.&lt;/P&gt;
&lt;P&gt;4. Open the Visual Basic Editor and under Debug click “Compile VBAProject” &lt;/P&gt;
&lt;P&gt;5. Then save and redeploy the updated workbook&lt;/P&gt;
&lt;P&gt;Note: If you do not recompile the project on the development computer that has a design time license for the control. When you open the open the workbook on a client computer you will receive the following error &lt;B&gt;“License information for this component not found. You do not have an appropriate license to use this functionality in the design environment.”&lt;/B&gt; This is because the runtime time license is stored with the ActiveX control within the workbook and by re-compiling the control on the development computer the run time license is correctly updated.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;On Client Computer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. Delete the cached versions of the control type libraries (extender files). To do this, search your hard drive for ".exd," and delete all the .exd files. The .exd files will be re-created automatically using the new controls the next time that you use VBA. The extender files will reside under the users profile and may reside in multiple locations such as:&lt;/P&gt;
&lt;P&gt;C:\documents and settings\username\Application Data\Microsoft\Forms&lt;/P&gt;
&lt;P&gt;C:\documents and settings\username\AppData\Local\Temp\VBE&lt;/P&gt;
&lt;P&gt;Note that you can search the "HKEY_CLASSES_ROOT\TypeLib" key in the registry using the search term "exd" to find the locations where the extender files reside. &lt;/P&gt;
&lt;P&gt;2. Download the update control from the URL associated with the problem control into a browser window (see list below).&lt;/P&gt;
&lt;P&gt;COMCT232.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/comct232.cab" mce_href="http://activex.microsoft.com/controls/vb6/comct232.cab"&gt;http://activex.microsoft.com/controls/vb6/comct232.cab&lt;/A&gt; &lt;BR&gt;MSCHRT20.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/mschrt20.cab" mce_href="http://activex.microsoft.com/controls/vb6/mschrt20.cab"&gt;http://activex.microsoft.com/controls/vb6/mschrt20.cab&lt;/A&gt; &lt;BR&gt;MSCOMCT2.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/mscomct2.cab" mce_href="http://activex.microsoft.com/controls/vb6/mscomct2.cab"&gt;http://activex.microsoft.com/controls/vb6/mscomct2.cab&lt;/A&gt; &lt;BR&gt;MSDATGRD.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/msdatgrd.cab" mce_href="http://activex.microsoft.com/controls/vb6/msdatgrd.cab"&gt;http://activex.microsoft.com/controls/vb6/msdatgrd.cab&lt;/A&gt; &lt;BR&gt;MSFLXGRD.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/msflxgrd.cab" mce_href="http://activex.microsoft.com/controls/vb6/msflxgrd.cab"&gt;http://activex.microsoft.com/controls/vb6/msflxgrd.cab&lt;/A&gt; &lt;BR&gt;MSHFLXGD.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/mshflxgd.cab" mce_href="http://activex.microsoft.com/controls/vb6/mshflxgd.cab"&gt;http://activex.microsoft.com/controls/vb6/mshflxgd.cab&lt;/A&gt; &lt;BR&gt;MSMASK32.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/msmask32.cab" mce_href="http://activex.microsoft.com/controls/vb6/msmask32.cab"&gt;http://activex.microsoft.com/controls/vb6/msmask32.cab&lt;/A&gt; &lt;BR&gt;MSWINSCK.OCX - &lt;A href="http://activex.microsoft.com/controls/vb6/mswinsck.cab" mce_href="http://activex.microsoft.com/controls/vb6/mswinsck.cab"&gt;http://activex.microsoft.com/controls/vb6/mswinsck.cab&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;3. When prompted, choose to Save the file to client computer.&lt;/P&gt;
&lt;P&gt;4. Extract the files from the .CAB&lt;/P&gt;
&lt;P&gt;5. Browse to the location of the extracted files.&amp;nbsp; Right-click on the .INF file, &lt;BR&gt;and choose 'Install' (this should take a matter of a couple of seconds and there &lt;BR&gt;will be no confirmation message)&lt;/P&gt;
&lt;P&gt;6. Click on Start, then Run, type in 'regsvr32 &amp;lt;OCXNAME&amp;gt;.ocx' (excluding quotes, &lt;BR&gt;substituting the name of the control that was just installed) and click on 'OK'.&lt;/P&gt;
&lt;P&gt;7. A message stating the 'DllRegisterServer in &amp;lt;controlname&amp;gt;.ocx succeeded.'&amp;nbsp; &lt;BR&gt;Click 'OK'.&lt;/P&gt;
&lt;P&gt;8. Open the re-complied workbook to ensure that the control is working.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Other options&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There are two additional workarounds&lt;/P&gt;
&lt;P&gt;1. Remove the kill bit for the ActiveX control; this means that the security vulnerabilities are still exposed. (this is not recommended)&lt;/P&gt;
&lt;P&gt;2. To remove the AlternateCLSID and keep the Kill Bit; this will cause the control not to load. &lt;/P&gt;
&lt;P&gt;When security advisory 960715 is applied, the following two registry keys are added for each control listed above. Example:&lt;/P&gt;
&lt;P&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\ &lt;/P&gt;
&lt;P&gt;{CLSID of killed ActiveX control}, Compatibility Flags, 0x0400&lt;/P&gt;
&lt;P&gt;*This is the actual Kill Bit, 0x400, which is “COMPAT_EVIL_DONT_LOAD” which means the control is never used.&lt;/P&gt;
&lt;P&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\ &lt;/P&gt;
&lt;P&gt;{CLSID of killed ActiveX control}&lt;/P&gt;
&lt;P&gt;This registry key is referred to as the Phoenix-Bit, a.k.a AlternateCLSID. Since a Kill-Bit completely prevents a control from loading, this key points to the updated controls GUID.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Workaround one&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Change the Compatibility Flags to 0x00800000 which means Safe for Loading. The information regarding Compatibility Flags can be found at &lt;A href="http://msdn.microsoft.com/en-us/library/aa768234.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa768234.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa768234.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Workaround Two&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Remove the AlternateCLSID registry key, this will remove the control from the form. &lt;/P&gt;
&lt;P&gt;*With both of these workarounds, once you install the check security advisory, you must make the same changes again because registry keys revert to the Kill bit behavior.&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;&lt;/FORM&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Author: Lee Kohrman)&lt;/P&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9700609" width="1" height="1"&gt;</content><author><name>praveenb</name><uri>http://blogs.msdn.com/members/praveenb.aspx</uri></author></entry><entry><title>How to merge two or more Word 2003 or Word 2007 XML documents into one Word 2007 XML document.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/04/14/how-to-merge-two-or-more-word-2003-or-word-2007-xml-documents-into-one-word-2007-xml-document.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/04/14/how-to-merge-two-or-more-word-2003-or-word-2007-xml-documents-into-one-word-2007-xml-document.aspx</id><published>2009-04-14T03:31:41Z</published><updated>2009-04-14T03:31:41Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;Here are the steps to merge the documents.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;Open a new Microsoft Word 2007 document and type &lt;/p&gt; &lt;p&gt;A&lt;br&gt;B&lt;br&gt;C  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image002_thumb.jpg" width="352" height="283"&gt;&lt;/a&gt;  &lt;p&gt;Save the document to C:\Source.xml. Please change the “Save As Type” to “Word XML Document”.  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;u&gt; &lt;/u&gt;&lt;br&gt;&lt;br&gt;Open a new Microsoft Word 2007 document and type  &lt;p&gt;D&lt;br&gt;E&lt;br&gt;F  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image004_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image004_thumb.jpg" width="380" height="256"&gt;&lt;/a&gt;  &lt;p&gt;Save the document to C:\ Destination.xml. Please change the “Save As Type” to “Word XML Document”.  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 3&lt;/u&gt;:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;&lt;br&gt;Open Source.xml in Visual Studio and add a package part to hold the content to be merged. Please note that content type is being used i.e. application/xml.  &lt;p&gt;&amp;lt;pkg:part pkg:name="/word/embed/destination.xml" pkg:contentType="application/xml"&amp;gt;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;pkg:xmlData&amp;gt;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/pkg:xmlData&amp;gt;  &lt;p&gt;&amp;lt;/pkg:part&amp;gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 4&lt;/u&gt;:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;&lt;br&gt;In Source.xml, add a relationship in document.xml.rels section.&lt;/p&gt; &lt;p&gt;&amp;lt;Relationship Id="afChunkId1" Type="&lt;a href="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk"&gt;http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk&lt;/a&gt;" Target="/word/embed/destination.xml"/&amp;gt;  &lt;p&gt;Please note that value of the Target attribute should be the same as specified in step 3 for pkg:name attribute.  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 5&lt;/u&gt;:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;&lt;br&gt;Please specify the following element in document.xml. This element should appear where you would like to see the merged data.  &lt;p&gt;&amp;lt;w:altChunk r:id="afChunkId1" xmlns:r="&lt;a href="http://schemas.openxmlformats.org/officeDocument/2006/relationships"&gt;http://schemas.openxmlformats.org/officeDocument/2006/relationships&lt;/a&gt;"/&amp;gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 6&lt;/u&gt;:&lt;/em&gt;&lt;/strong&gt;&amp;nbsp; &lt;br&gt;&lt;br&gt;Now open&amp;nbsp; destination.xml, copy everything except the processing instructions and paste in between &amp;lt;pkg:xmlData&amp;gt; element specified in step 3 in Source.xml.&amp;nbsp; Please note that you can also merge the Word 2003 XML document by just copying the XML except the processing instructions and pasting in between &amp;lt;pkg:xmlData&amp;gt; element.  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;br&gt;&lt;u&gt;Step 7&lt;/u&gt;:&lt;/em&gt;&lt;/strong&gt;&amp;nbsp; &lt;br&gt;&lt;br&gt;Save Source.xml and open it in Word and you will see that data is merged.  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image006_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image006" src="http://blogs.msdn.com/blogfiles/vsod/WindowsLiveWriter/HowtomergetwoormoreWord2003orWord2007XM_53D9/clip_image006_thumb.jpg" width="399" height="275"&gt;&lt;/a&gt;  &lt;p&gt;Reference Links&lt;br&gt;=========================  &lt;ul&gt; &lt;li&gt;Please download the ECMA-376 1st edition Part 4 from the following site. The specification for Altchunk is explained in the 4&lt;sup&gt;th&lt;/sup&gt; part.&lt;br&gt;&lt;a href="http://www.ecma-international.org/publications/standards/Ecma-376.htm"&gt;http://www.ecma-international.org/publications/standards/Ecma-376.htm&lt;/a&gt;  &lt;li&gt;Leveraging content in other formats&lt;br&gt;&lt;a href="http://blogs.msdn.com/brian_jones/archive/2007/01/17/leveraging-content-in-other-formats.aspx"&gt;http://blogs.msdn.com/brian_jones/archive/2007/01/17/leveraging-content-in-other-formats.aspx&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The following link explains as how Altchunk element can be used to merge the Open XML documents using Open XML SDK.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Creating Documents by Using the Open XML Format SDK 2.0 (Part 3 of 3)&lt;br&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd469465.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd469465.aspx&lt;/a&gt;  &lt;li&gt;How to Use altChunk for Document Assembly&lt;br&gt;&lt;a href="http://blogs.msdn.com/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx"&gt;http://blogs.msdn.com/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx&lt;/a&gt;  &lt;li&gt;AltChunk Class (DocumentFormat.OpenXml.Wordprocessing)&lt;br&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.altchunk(office.14).aspx"&gt;http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.altchunk(office.14).aspx&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9547623" width="1" height="1"&gt;</content><author><name>Ankush Bhatia</name><uri>http://blogs.msdn.com/members/Ankush+Bhatia.aspx</uri></author></entry><entry><title>Word 2003 SP3 throws intermittent error - There is insufficient memory. Save the document now</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/vsod/archive/2009/03/16/word-2003-sp3-throws-intermittent-error-there-is-insufficient-memory-save-the-document-now.aspx" /><id>http://blogs.msdn.com/vsod/archive/2009/03/16/word-2003-sp3-throws-intermittent-error-there-is-insufficient-memory-save-the-document-now.aspx</id><published>2009-03-16T16:07:00Z</published><updated>2009-03-16T16:07:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;Summary&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;An application automating Word 2003 SP3 intermittently throws below exception from Open method:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;"System.Runtime.InteropServices.COMException (0x800A13E9): There is insufficient memory. Save the document now."&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;Symptoms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Error Message: There is insufficient memory. Save the document now&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;Cause&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;This is a generic error message which can arise due to multiple reasons (most of the time, it’s due to an actual memory issue), but in this specific case, error arises when there are a lot of word temporary files.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;Resolution&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;B&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;1) Delete temporary files from %Temp% folder (Go to start-&amp;gt;Run, type %Temp% and hit enter).&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;2) Delete temporary files from &amp;lt;Temporary Internet Files&amp;gt;\Content.Word folder. "Temporary Internet Files" folder can be found by opening "Internet Explorer-&amp;gt;Tools-&amp;gt;Options-&amp;gt;General Tab-&amp;gt;Browsing history-&amp;gt;Settings-&amp;gt;View Files". &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Note: Word writes temporary files to above folders and sometimes these files cannot be deleted due to abnormal exit of Word instance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="COLOR: #1f497d; mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9481348" width="1" height="1"&gt;</content><author><name>Shiv Khare</name><uri>http://blogs.msdn.com/members/Shiv+Khare.aspx</uri></author><category term="Automation" scheme="http://blogs.msdn.com/vsod/archive/tags/Automation/default.aspx" /><category term="Word" scheme="http://blogs.msdn.com/vsod/archive/tags/Word/default.aspx" /><category term="Troubleshooting" scheme="http://blogs.msdn.com/vsod/archive/tags/Troubleshooting/default.aspx" /><category term="COM AddIns" scheme="http://blogs.msdn.com/vsod/archive/tags/COM+AddIns/default.aspx" /><category term="Office" scheme="http://blogs.msdn.com/vsod/archive/tags/Office/default.aspx" /></entry></feed>