Created
September 7, 2011 05:34
-
-
Save crazyfool2100/1199844 to your computer and use it in GitHub Desktop.
A host ExcelDna add-in loading and unloading another 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="Host Add-In" Language="CS" RuntimeVersion="v4.0"> | |
<Reference AssemblyPath="System.Windows.Forms.dll"/> | |
<Reference Name="Microsoft.Office.Interop.Excel" /> | |
<![CDATA[ | |
using System; | |
using ExcelDna.Integration; | |
using System.Windows.Forms; | |
using Excel = Microsoft.Office.Interop.Excel; | |
public class HostAddIn: IExcelAddIn | |
{ | |
private static string xll_path = @"Z:\UnloadXll\Add-In\add-in.xll"; | |
public void AutoOpen() | |
{ | |
Excel.Application XL = (Excel.Application)ExcelDnaUtil.Application; | |
XL.RegisterXLL(HostAddIn.xll_path); | |
double now = (double)XlCall.Excel(XlCall.xlfNow); | |
XlCall.Excel(XlCall.xlcOnTime, now, "UnloadAddIn"); | |
} | |
public void AutoClose() | |
{ | |
} | |
public static void UnloadAddIn() | |
{ | |
object removeId = XlCall.Excel(XlCall.xlfRegister, HostAddIn.xll_path, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2); | |
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId); | |
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister, removeId); | |
MessageBox.Show("The add-in has been disabled.", "Unload Add-In"); | |
} | |
} | |
]]> | |
</DnaLibrary> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment