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;
}
}
}
Public Shared Sub Addins_COM_Connect(ByVal sDescription As String, _
ByVal bConnect As Boolean)

Dim objComAddins As Office.COMAddIns
Dim objComAddin As Office.COMAddIn

objComAddins = gApplicationExcel.COMAddIns

For Each objComAddin In objComAddins

If sDescription = objComAddin.Description Then
objComAddin.Connect = bConnect
Exit Sub
End If

Next objComAddin

End Sub

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;
}
}
}
Public Shared Function Addins_COM_ConnectState(ByVal sDescription As String) As Boolean

Dim objComAddins As Office.COMAddIns
Dim objComAddin As Office.COMAddIn

objComAddins = gApplicationExcel.COMAddIns

For Each objComAddin In objComAddins

If sDescription = objComAddin.Description Then
COMAddin_ConnectState = objComAddin.Connect
Exit Function
End If

Next objComAddin

End Function

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;
}
Public Shared Function Addins_COM_Exists(ByVal sDescription As String) As Boolean

Dim objComAddins As Office.COMAddIns
Dim objComAddin As Office.COMAddIn

objComAddins = gApplicationExcel.COMAddIns

For Each objComAddin In objComAddins

If sDescription = objComAddin.Description Then
COMAddin_Exists = True
Exit Function
End If

Next objComAddin

COMAddin_Exists = False

End Function

Addins_COM_ListAll

public static void Addins_COM_ListAll()
{
Office.COMAddIns objComAddins;
Office.COMAddIn objComAddin;

objComAddins = gApplicationExcel.COMAddIns;

foreach (var objComAddin in objComAddins)
{
MsgBox(
"GUID: " + objComAddin.Guid + Constants.vbCrLf +
"Project ID: " + objComAddin.ProgId + Constants.vbCrLf +
"Creator: " + objComAddin.Creator + Constants.vbCrLf +
"Connect: " + objComAddin.Connect + Constants.vbCrLf +
"Description: " + objComAddin.Description);
}
}
Public Shared Sub Addins_COM_ListAll()

Dim objComAddins As Office.COMAddIns
Dim objComAddin As Office.COMAddIn

objComAddins = gApplicationExcel.COMAddIns

For Each objComAddin In objComAddins

Call MsgBox("GUID: " & objComAddin.Guid & vbCrLf & _
"Project ID: " & objComAddin.ProgId & vbCrLf & _
"Creator: " & objComAddin.Creator & vbCrLf & _
"Connect: " & objComAddin.Connect & vbCrLf & _
"Description: " & objComAddin.Description)

Next objComAddin

End Sub

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);

// sets the flag to an error
clsError.ErrorFlagChange(true);
}
Public Shared Sub Message_AddinHasExpired()

If clsError.ErrorFlag() = True Then Exit Sub

Call 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)

'sets the flag to an error
clsError.ErrorFlagChange(True)
End Sub

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);

// sets the flag to an error
clsError.ErrorFlagChange(true);
}
Public Shared Sub Message_AddinNotInstalledCorrectly()

If clsError.ErrorFlag() = True Then Exit Sub

Call 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)

'sets the flag to an error
clsError.ErrorFlagChange(True)
End Sub

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);

// sets the flag to an error
clsError.ErrorFlagChange(true);
}
Public Shared Sub Message_AddinOnlyForTesting()

If clsError.ErrorFlag() = True Then Exit Sub

Call 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)

'sets the flag to an error
clsError.ErrorFlagChange(True)
End Sub

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top