C# Snippets
Addins_COM_Connect
public static void Addins_COM_Connect(
string sDescription,
bool bConnect)
{
Office.COMAddIns objComAddins;
Office.COMAddIn objComAddin;
objComAddins = gApplicationExcel.COMAddIns;
foreach (var objComAddin in objComAddins)
{
if (sDescription == objComAddin.Description)
{
objComAddin.Connect = bConnect;
return;
}
}
}
Addins_COM_ConnectState
public static bool Addins_COM_ConnectState(
string sDescription)
{
Office.COMAddIns objComAddins;
Office.COMAddIn objComAddin;
objComAddins = gApplicationExcel.COMAddIns;
foreach (var objComAddin in objComAddins)
{
if (sDescription == objComAddin.Description)
{
COMAddin_ConnectState = objComAddin.Connect;
return;
}
}
}
Addins_COM_Exists
public static bool Addins_COM_Exists(
string sDescription)
{
Office.COMAddIns objComAddins;
Office.COMAddIn objComAddin;
objComAddins = gApplicationExcel.COMAddIns;
foreach (var objComAddin in objComAddins)
{
if (sDescription == objComAddin.Description)
{
COMAddin_Exists = true;
return;
}
}
COMAddin_Exists = false;
}
Addins_COM_ListAll
public static void Addins_COM_ListAll()
{
Office.COMAddIns objComAddins;
Office.COMAddIn objComAddin;
objComAddins = gApplicationExcel.COMAddIns;
foreach (var objComAddin in objComAddins)
{
System.Windows.Forms.MessageBox.Show(
"GUID: " + objComAddin.Guid + Constants.vbCrLf +
"Project ID: " + objComAddin.ProgId + Constants.vbCrLf +
"Creator: " + objComAddin.Creator + Constants.vbCrLf +
"Connect: " + objComAddin.Connect + Constants.vbCrLf +
"Description: " + objComAddin.Description);
}
}
Addins_VBA_ListAll
public static void Addins_List()
{
Excel.Range objRange;
int iaddincount;
try
{
for (iaddincount = 1; iaddincount <= gApplicationExcel.AddIns.Count; iaddincount++)
{
objRange = gApplicationExcel.Cells.get_Range("A" + iaddincount, System.Type.Missing);
objRange.Value2 = gApplicationExcel.AddIns.get_Item(iaddincount).Name;
objRange = gApplicationExcel.Cells.get_Range("B" + iaddincount, System.Type.Missing);
objRange.Value2 = gApplicationExcel.AddIns.get_Item(iaddincount).FullName;
objRange = gApplicationExcel.Cells.get_Range("C" + iaddincount, System.Type.Missing);
objRange.Value2 = gApplicationExcel.AddIns.get_Item(iaddincount).Installed;
objRange = gApplicationExcel.Cells.get_Range("D" + iaddincount, System.Type.Missing);
objRange.Value2 = gApplicationExcel.AddIns.get_Item(iaddincount).Path;
}
}
catch { }
finally { }
}
Message_AddinHasExpired
public static void Message_AddinHasExpired()
{
if (clsError.ErrorFlag() == true)
{
return;
}
System.Windows.Forms.MessageBox.Show(
"The " + gobjSolution.OfficeAppName + " add-in '" + gobjSolution.SolutionName +
"' has now expired and should be removed." +
System.Environment.NewLine +
System.Environment.NewLine +
"Untick this add-in from the (Tools > COM Add-ins) dialog box to stop this message from appearing." +
System.Environment.NewLine +
System.Environment.NewLine +
"For more information about this add-in please contact us." +
System.Environment.NewLine +
"You can send us an email 'support@bettersolutions.com' or visit the website.",
gobjSolution.SolutionFormPrefix + "Add-in Expired",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
clsError.ErrorFlagChange(true);
}
Message_AddinNotInstalledCorrectly
public static void Message_AddinNotInstalledCorrectly()
{
if (clsError.ErrorFlag() == true)
{
return;
}
System.Windows.Forms.MessageBox.Show(
"The '" + gobjSolution.SolutionName + "' add-in has not been installed correctly." +
System.Environment.NewLine +
System.Environment.NewLine +
"Please contact your IT support team.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
clsError.ErrorFlagChange(true);
}
Message_AddinOnlyForTesting
public static void Message_AddinOnlyForTesting()
{
if (clsError.ErrorFlag() == true)
{
return;
}
System.Windows.Forms.MessageBox.Show(
"The '" + gobjSolution.SolutionName + "' add-in currently installed was only for test " +
"purposes and has now expired." +
System.Environment.NewLine +
System.Environment.NewLine +
"This add-in should be uninstalled." +
System.Environment.NewLine +
System.Environment.NewLine +
"If you want to find out more about this add-in, " +
"please visit the BetterSolutions.com website.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
clsError.ErrorFlagChange(true);
}
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top