We translated your VBA sample into C# code we hoped would be accessible from "OurNewAddin".
using JChemExcelCOMInterfacesLib;
using Microsoft.Office.Interop.Excel;
using Application=Microsoft.Office.Interop.Excel.Application;
...
Application app = Globals.OurNewAddin.Application;
//Also tried: Application app = Globals.OurNewAddin.Application.Parent;
string appName = app.Name; // appName is equal to “Microsoft Excel”
var addins = app.COMAddIns;
object jChemAddinStringObject = "JChemExcel.JChemExcelAddin";
COMAddIn objAddin = addins.Item(ref jChemAddinStringObject);
//Also tried: object objAddin = addins.Item(ref ChemAddinStringObject).Object;
IJChemExcelAPI jeJchemForExcel = (IJChemExcelAPI)objAddin.Object;
string[] structures = { "C1=CC=CC=C1","C1=CC2=C(C=C1)C=CC=C2" };
Workbook workbook = (Workbook)Globals.OurNewAddin.Application.ActiveWorkbook;
Worksheet worksheet = (Worksheet)Globals.OurNewAddin.Application.ActiveSheet;
jeJchemForExcel.AddStructuresToColumn(structures, "smiles", 1,"Demo header", workbook.Name, worksheet.Name, 1);
But this attempt failed with a method access exception upon executing AddStructuresToColumn
System.MethodAccessException: Attempt to access the method failed.
at JChemExcelCOMInterfacesLib.IJChemExcelAPI.AddStructuresToColumn(Array
structures, String Format, Int32 column, Object header, Object workbookName,
Object worksheetName, Object startRow)
However, we do notice that the code above works after we "manually start" JC4XL by clicking any of the JChem ribbon items.
JChem seems to then load (and display its splash screen), making it available for use from other plugins. This brings us tantalizingly close to our goal.
Do you have any ideas on how we might trigger JC4XL to load into memory without clicking the ribbon buttons?
Thanks in advance,
Brett
Application app
= Globals.HeliumAddIn.Application;
//app =
Globals.HeliumAddIn.Application.Parent; I also tried with
this instruction
string
appName = app.Name; // appName is equal to
“Microsoft Excel”
var addins
= app.COMAddIns;
object
jChemAddinStringObject = "JChemExcel.JChemExcelAddin";
COMAddIn objAddin
= addins.Item(ref jChemAddinStringObject);
IJChemExcelAPI
jeJchemForExcel = (IJChemExcelAPI)objAddin.Object;
string[] structures = { "C1=CC=CC=C1",
"C1=CC2=C(C=C1)C=CC=C2" };
Workbook
workbook = (Workbook)Globals.HeliumAddIn.Application.ActiveWorkbook;
try
{
jeJchemForExcel.AddStructuresToColumn(structures, "smiles",
1,
"Demo header", workbookName,
worksheetName, 1);
}
catch (Exception
exc)
{
string exceptionMsg = exc.Message;
}