title: How to remove an Excel UDF programmatically
body: <p>I have an old Excel addin (written in VBA), now I re-write the old addin using .NET, ExcelDNA, NetOffice.  In the old addin, there is a UDF, say, OldUDF, in the new addin, there is a NewUDF, the two UDFs do the same thing and accept the same parameters.  but they have different function names.
  For legacy reason, some clients have old addin, some clients have new addin. 
  Some client have both. 
  When they have both Excel addin installed, I want to provide a checkbox which says forward oldUDF to newUDF in the new addin. When the checkbox is checked, oldUDF is forwarded as newUDF. When the checkbox is not checked, oldUDF will not be forwarded.
  I define the oldUDF &amp; newUDF in the new addin but do not know how to remove the definiatino of the oldUDF when the checkbox is unchecked.  Thanks </p>
  
  <p>Edit:</p>
  
  <p>Here is what I tried, but it is not working.</p>
  
  <pre><code>#if FORWARD
          public static object OldUDF([ExcelArgument(AllowReference = true, Name = "Symbol",
              Description = "is a futures symbol as defined in *** Database.")]string symbol,
              [ExcelArgument(AllowReference = true, Name = "Column",
                  Description = "is a column associated with a symbol")]string column,
              [ExcelArgument(AllowReference = true, Name="Date",
                  Description = "is the date for which you want the value")]object onDate,
                  object fillOpt, object frequency)
          {
              return NewUDF(symbol, column, onDate, fillOpt, frequency);
          }
  #endif 
  </code></pre>
  
  <p>In AutoOpen(), 
  I will read the forward value (true or false) from a file,  if forward is true,  </p>
  
  <pre><code>        var forward = Helper.ReadForwardOldUDFSettingFromAFile();
          if(forward)
          {
               #define FORWARD
          }
  </code></pre>
  
  <p>but I get a compile error </p>
  
  <p>Edit again:
  I managed to register successfully 
  I put declaration of OldUDF in a seperate dll, say oldUDF.dll 
  create another oldUDF.xll, oldUDF.dna. </p>
  
  <p>In AutoOpen, I will check if the forward value (from a file) is true, I will do 
  Excel.Application.RegisterXLL("olderUDF.xll");
  This works fine. </p>
  
  <p><strong>However, in case of the forward value is false, I can't find a way to un-register or remove the XLL in C#?</strong> </p>
  
  <p>Edit: I found <a href="http://msdn.microsoft.com/en-us/library/office/bb687866.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/office/bb687866.aspx</a>, but not sure how to use it in C#</p>
  
  <p>Thanks </p>