Created
September 7, 2011 09:48
-
-
Save govert/1200178 to your computer and use it in GitHub Desktop.
Excel-DNA (http://excel-dna.net) sample showing how to load/unload other add-ins from a host add-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DnaLibrary Name="AddInHost" Language="C#" RuntimeVersion="v4.0"> | |
<Reference Name="System.Windows.Forms" /> | |
<![CDATA[ | |
using System; | |
using System.Windows.Forms; | |
using ExcelDna.Integration; | |
public class MyMacros | |
{ | |
public static object registerId; | |
[ExcelCommand(MenuName="AddinHost", MenuText="Load Addin")] | |
public static void LoadAddin() | |
{ | |
XlCall.XlReturn result = XlCall.TryExcel(XlCall.xlfRegister, out registerId, @"C:\Work\ExcelDna\Samples\MetaAddin\AddIn.xll"); | |
} | |
[ExcelCommand(MenuName="AddinHost", MenuText="Unload Addin")] | |
public static void UnloadAddin() | |
{ | |
MessageBox.Show("About to call xlAutoRemove."); | |
string theName = @"C:\Work\ExcelDna\Samples\MetaAddin\AddIn.xll"; | |
object removeId = XlCall.Excel(XlCall.xlfRegister, theName, "xlAutoRemove", "I" , ExcelMissing.Value, ExcelMissing.Value, 2); | |
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId); | |
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister, removeId); | |
object success = XlCall.Excel(XlCall.xlfUnregister, registerId); | |
MessageBox.Show("Result of Unregister: " + success.ToString() ); | |
} | |
} | |
public static class MyFunctions | |
{ | |
public static string AddinHostTestFunction() | |
{ | |
return "Hello from the add-in host!"; | |
} | |
[ExcelCommand(MenuName="AddinHost", MenuText="Say Hello!")] | |
public static void AddIn() | |
{ | |
MessageBox.Show("Hello from the add-in host!"); | |
} | |
} | |
]]> | |
</DnaLibrary> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment