unload Smart Document on initialize

I'm writing a smart document with VSTO1 (VSNET2003) and excel.

I've implement "ISmartDocument" and in Sub "SmartDocInitialize" i make a test (like license).

If this test go bad i want to unload the smart document, so that the document is a simple workseet of excel.

The problem if that i'm not be able to do that. I've tryed so:

Dim oWo As Excel.Workbook = CType(Document, Excel.Workbook)
oWo.Saved = True
oWo.Close()

but Excel crash ad ask the re-start of the application.

Any Suggestion




Answer this question

unload Smart Document on initialize

  • Daan van Schaijk

    Unloading smart document from SmartDocInitialize creates bad re-entrancy problems for Excel. Instead, you can just throw an exception from SmartDocInitialize:

    const int E_ABORT = unchecked((int)0x80004004);

    throw new COMException("error", E_ABORT);



  • unload Smart Document on initialize