Subscribe to the RSS feed then follow me on twitter at @mrlacey

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

If you've built Windows Phone or Windows Store apps you can cross-promote them with AdDuplex to get more users.

No comments:

Post a Comment