C# Snippets


Addins_COM_Connect

.
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 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 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 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 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 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 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

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