Hi Preston,
Are you running this code from an external application like a console app, or from a macro inside an Excel add-in?
I assume the former. The Excel-DNA project is making Excel add-ins, so might not be the best place for general Excel programming support.
You should not need to call Marshal.ReleaseComObject to clean things up, just structure the code so that you can run the GC after all the Excel work is complete.
See my Stackoverflow answer here: https://stackoverflow.com/a/38111137/44264
It might help you to check whether similar code works from VBA.
That could at least pin down the exact call, and maybe a better error message.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/a7585141-2fd5-4628-b199-e45ef46c4165n%40googlegroups.com.
With the F# code you show
let xlApp = new ApplicationClass(Visible = true, DisplayAlerts = true)
I don’t know what this will do from inside the add-in – whether it opens a separate Excel process, or connect to the current Excel instance where the ad-in is running.
I suggest you run the code in the same Excel instance as the add-in, and that you get hold of the Excel root Application object by calling
“ExcelDnaUtil.Application” – the return type is object, but you can cast to an “Microsoft.Office.Interop.Excel.Application” type.
Then you must definitely remove all the ReleaseObject calls, and also not Quit the application.
If you then still have a problem, you need to identify the exact line, and try to match with what happens in the matching VBA.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/6665b5b4-ef74-42fd-92aa-cd284d3db029n%40googlegroups.com.