Excel Automation question
I am trying to start Excel through code. My objective is to start excel and load a Addin called TM1. If i go in through explorer and click on this Addin(.xla) it connects to a datawarehouse and adds a menu item in excel called Tm1.
Well here is the code that I am using to accomplish the above tasks:
try
{
//create a new excel app.
_newApp = new Excel.Application();
_newApp.Visible = true;
_newApp.AddIns.Add("C:\\Applix\\Integra\\bin\\tm1p.xla","C:\\Applix\\Integra\\bin\\tm1.xla");
_userBook = (Excel._Workbook)_newApp.Workbooks.Add("C:\\Inetpub\\wwwroot\\ExcelAddinExample\\ExcelTemplates\\01_fsTemplate_orig.xls");
_tm1Book = _newApp.Workbooks.Open("C:\\Applix\\Integra\\bin\\tm1.xla",0,false,5,"","",true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,false,null,null);
//try to call the copnnect routine;
_newApp.Run("N_Connect","toad","bisu","GBA03",null,null,null,null,null,null
,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null);
}
Well my code is failing at the Addins.Add() line. What am i doing wrong.
The error message i get is
{"Add method of AddIns class failed" }
and unfortualty the stack trace is not very descriptive either. But here it is:
" at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Excel.AddIns.Add(String Filename, Object CopyFile)\r\n at ExcelModel.ExcelHandler.CreateExcel() in c:\\sameer work area\\excelmodel\\excelhandler.cs:line 32"
I copied this directly from the debugger.
What am i doing wrong.
Sameer