Monday, January 14, 2008

Automating NOW() + N in Excel

Back in December I noted about skipping weekends in Excel date calculations.

Have just got round to getting this working with automation from C#.

Here's the code:


//Open the Add-in workbook
objBooks.Open(((Excel.ApplicationClass)(((Excel.Application)(objBooks.Application)))).LibraryPath + @"\Analysis\ANALYS32.XLL", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

//must install add-in for it to work
//can only install if it is not installed already
objAddIn = objApp.AddIns.Add(((Excel.ApplicationClass)(((Excel.Application)(objBooks.Application)))).LibraryPath + @"\Analysis\ANALYS32.XLL", true);
if (objAddIn.Installed)
objAddIn.Installed = false;
objAddIn.Installed = true;

//Register the Add-in
objApp.RegisterXLL("ANALYS32.XLL");

//Run the auto-open macros in the workbook
objApp.ActiveWorkbook.RunAutoMacros(Excel.XlRunAutoMacro.xlAutoOpen);

0 comments:

Post a Comment

I get a lot of comment spam :( - moderation may take a while.