This namespace contains a set of types that extend and support the Microsoft Excel object model
This includes the following types:

  • WorkbookBase and WorksheetBase classes - These are base classes for the ThisWorkbook and SheetN classes in document-level solutions

  • Workbook and Worksheet interfaces - These can be created at run-time in application-level solutions

  • Types used for SmartTag functionality

  • Various helper types, such as event arguments and delegates

  • Extended Objects - Host Items and Controls

You can access these item directly without having to traverse the Office object model.
Objects in this namespace are often referred to as VSTO objects.
VSTO supports adding both host items and host controls dynamically.
These are added to the Worksheet Controls collection
Excel controls tab of the toolbox in Visual Studio
Only the controls that can be added at design time are displayed on the toolbox

Why Bother

In document level customisations you might want to run some code when the user interacts with an object in your document level solution, but not when the user interacts with a similar object in another file.
When you have a Native object you can test whether that object has been extended using the GetVstobject and HasVstoObject methods.


If you ever need to pass the aggregate to an Excel object model method that requires the real com Excel object, you can obtain this by using the "InnerObject" property

GetVSTOObject Method

You can get a VSTO host item from the PIA object for a Document using the GetVSTOObject method.
VSTO uses a new language feature called extension methods to extend the Microsoft.Office.Interop.Word.Document with a method called GetVSTOObject.

Dim vstoDocument As Microsoft.Office.Tools.Word.Document 
vstoDocument = Globals.ThisAddin.Application.ActiveDocument.GetVSTOObject

You should use the ShutDown event on the document for a Close event as this is fired after any "do you want to save" dialog boxes

© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited