Microsoft.Office.Tools

This consists of managed assemblies that provide the communication layer between Office and your solution.
All these assemblies are installed when the VSTO Runtime is installed.
These extensions are specific assemblies that your solution will use in order to automate and extend an Office application.
When you create an Office solution in Visual Studio references to these assemblies will be added automatically depending on the type of solution you are creating.
There are slightly different assemblies depending on which version of the .NET Framework you are using.


Microsoft.Office.Tools namespace

This namespace and assemblies contain a set of types that extend and support a specific object model.
For example in Excel, the Microsoft.Office.Tools.Excel namespace includes the host control objects (ListObject, NamedRange, Chart and XMLMappedRange).
This namespace also includes types that provide smart tag functionality, base class for application-levels add-ins and classes for creating custom task panes in add-ins.
Microsoft.Office.Tools.Excel
Microsoft.Office.Tools.Word
Microsoft.Office.Tools.Outlook
The installation of the Office Extensions for .NET Framework depends on the configuration of the computer and the methods of installation.
Install on Demand - If one of the Office Extensions cannot be installed when the runtime is installed the runtime will automatically install the missing office extension later when the requirements are met.

Methods of InstallationOffice Extensions for .NET 3.5Office Extensions for .NET 4.0Office Extensions for .NET 4.5
Runtime RedistributableInstalled if .NET 3.5 already installedInstalled if .NET 4.0 already installedInstalled if .NET 4.5 already installed
Office 2013Installed if .NET 3.5 already installedInstalled if .NET 4.0 already installed 
Office 2010 SP1Installed if .NET 3.5 already installedInstalled if .NET 4.0 already installed 
Office 2010Installed if .NET 3.5 already installed  

Microsoft.Office.Tools.AddInBase

This class defines the core functionality that is shared by all the VSTO add-ins created from the Development Tools in Visual Studio.
There is also an interface Microsoft.Office.Tools.Addin that defines a lot of core functionality.


Microsoft.Office.Tools.CustomTaskPane 
Microsoft.Office.Tools.CustomTaskPaneCollection
Microsoft.Office.Tools.EntryPoint
Microsoft.Office.Tools.Factory
Microsoft.Office.Tools.Factory.GetRibbonFactory
Microsoft.Office.Tools.Ribbon.IRibbonExtension
Microsoft.Office.Tools.Ribbon.OfficeRibbon
Microsoft.Office.Tools.Ribbon.RibbonBase
Microsoft.Office.Tools.Ribbon.RibbonBoxStyle
Microsoft.Office.Tools.Ribbon.RibbonFactory


Microsoft.Office.Tools.Excel

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.



InnerObject

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
this.NamedRangeItem.InnerObject



Host Items

Excel has three types of host items and their behaviour is all slightly different
Workbook
Worksheet
Chartsheet


Host Controls

The host items and host controls are in the Microsoft.Office.Tools.Excel namespace.
Host controls are built on top of native office objects and provide additional data binding and events
Native objects can be found in the Microsoft.Office.Interop.Excel namespace
Host controls can be found in the Microsoft.Office.Tools.Excel namespace
Worksheet - ListObject
Worksheet - NamedRange
Worksheet - Chart
Worksheet - XMLMappedRange
Worksheet - OLEObject


For a solution that dynamically creates host items in Excel, you must make sure that users of your solution have the "Trust access to Visual Basic project object model" checked

object temp = this.VBProject  //force VBA to initialize 

Using Document features in Application Level Add-ins

Starting with Visual Studio 2008 SP1 you can get a VSTO host item object for a document.
Once you have this host item you are able to use the Controls collection to add individual host controls.



If you add host controls at design-time and then the user accidentally deletes one and saves the document then a ControlNotFoundException will be generated the next time an event is listened for or a method is called.



It is difficult to prevent users from accidentally deleting controls unless the document is locked
It is possible to try and prevent design-time controls being deleted at run-time though.


Removing Controls

There are four ways to remove controls dynamically:

Controls.Delete 
ControlsCollection.Remove(control)
ControlsCollection.Remove(name)
ControlsCollection.RemoveAt(index)


Saving Host Controls

What happens if you add a host control dynamically and then the document is saved.
Host controls are part of the document so they will be saved although no information will persist.
If you want to reuse them you will have to reconnect the controls by adding them back to the ControlsCollection.


The ControlsCollection Add method lets you reconnect an existing control without creating a new on in the document.



Microsoft.Office.Tools.Word

This namespace contains a set of types that extend and support the Microsoft Word object model



Word-Interop-Host-Document

EventDescription131007
ActivateEvent Y  
BeforeClose Y  
BeforeDoubleClick Y  
BeforePrint Y  
BeforeRightClick Y  
BeforeSave Y  
BindingContextChanged Y  
BuildingBlockInsert (VBA) YYY
CloseEventOccurs when a document is closed. This is raised in situations where a document is not actually going to be closed. The event is fired before the "do you want to save" dialog is displayed. There is also an Application_DocumentBeforeClose event ?Y  
ContentControlAfterAdd (VBA)Occurs after a content control is added to a documentYYY
ContentControlBeforeContentUpdate (VBA) YYY
ContentControlBeforeDelete (VBA) YYY
ContentControlBeforeStoreUpdate (VBA) YYY
ContentControlOnEnter (VBA) YYY
ContentControlOnExit (VBA) YYY
Deactivate Y  
Disposed Y  
MailMergeAfterMerge Y  
MailMergeAfterRecordMerge Y  
MailMergeBeforeMerge Y  
MailMergeBeforeRecordMerge Y  
MailMergeDataSourceLoad Y  
MailMergeWizardSendToCustom Y  
MailMergeWizardStateChange Y  
New (VBA)Occurs when a new document based on the template is created. This will only run when the code is stored in the template.YYY
Open (VBA)Occurs when a document is opened.YYY
SelectionChange Y  
Shutdown Y  
Startup Y  
SyncEventOccurs when the local copy of a document is synchronized with a copy on the server that is part of a document workspace.Y  
WindowSize Y  
XMLAfterInsert (VBA)Occurs when a user adds a new XML element to a document. If more than one element is added to the document at the same time (for example cutting and pasting XML), the event fires for each element that is inserted. See belowYYY
XMLBeforeDelete (VBA)Occurs when a user deletes an XML element from a document. If more than one element is added to the document at the same time (for example when cutting and pasting XML), the event fires for each element that is inserted. See belowYYY


Word-Interop-Host-Document-Bookmark

EventDescription131007
BeforeDoubleClick    
BeforeRightClick    
DeSelected    
Selected    
SelectionChange    

In VBA the only way to detect when a user double clicks a bookmark is to declare an events class module declaring a withevents variable to the application object
Create the event and detect if the range overlaps with the bookmark in question.
In VSTO using the VSTO extensions this is much easier because the bookmark object itself sources the events so you just need to add

MyBookmark.BeforeDoubleClick += new ClickEventHandler(onDoubleClick) 



Creating Dynamically

These can be created dynamically


Microsoft.Office.Tools.Word.Bookmark AddBookmark( 
   Microsoft.Office.Interop.Word.Bookmark bookmark,
   string name);

Public Function AddBookmark (ByVal range As Microsoft.Office.Interop.Word.Range, _ 
                                  ByVal name As String) As Microsoft.Office.Tools.Word.Bookmark

Microsoft.Office.Tools.Word.Bookmark AddBookmark( 
   Microsoft.Office.Interop.Word.Range range,
   string name);



Word-Interop-Host-Document-Content-Control

ControlDescription131007
BuildingBlockGalleryContentControl    
ComboBoxContentControl    
ContentControl    
OLEControl    
DatePickerContentControl    
GroupContentControl    
PictureContentControl    
PlainTextContentControl    
RichTextContentControl    

All the content controls have these common events

EventDescription131007
Added YYY
BindingContextChanged YYY
ContentUpdating YYY
Deleting YYY
Entering YYY
Exiting YYY
StoreUpdating YYY
Validated YYY
Validating YYY


bookmark - addition BindingContextChanged ?



Word-Interop-Host-Document-XMLNode

EventDescription131007
AfterInsert YYY
BeforeDelete YYY
ContextError YYY
ContextLeave YYY
Deselect YYY
Select YYY
ValidationError YYY

These cannot be created dynamically at run-time



Word-Interop-Host-Document-XMLNodes

EventDescription131007
AfterInsert YYY
BeforeDelete YYY
BindingContextChanged    
ContextError YYY
ContextLeave YYY
Deselect YYY
Select YYY
ValidationError YYY


These cannot be created dynamically at run-time




Microsoft.Office.Tools.Outlook

This namespace contains a set of types that extend and support the Microsoft Outlook object model


Form Region


The only real difference between the VSTO 2005 Outlook 2003 add-in and the add-ins in VSTO 2005 SE is that the add-in host item base class wraps the Outlook Application PIA object
VSTO does not add any functionality to the Outlook object model
VSTO does not create any host items or host controls


Outlook Add-ins

These differ from Excel and Word add-ins because they must be registered in the registry
This means you must use a Setup Project to install your add-in.
When you create an Outlook add-in a setup project is automatically created for you ??
Outlook add-ins do not support Smart Tags, Task Pane Customisation or Data Caching.



Security

The security requirements of Outlook add-ins match those of Excel and Word document-level customisation.
By default VSTO solutions are very secure and require Code Access Security (CAS)
The security model in Outlook 2003 was improved with an email security update to help protect users from email viruses
This security model (often referred to as the Outlook Object Model Guard) prevents access to certain members of the Outlook object model.
It automatically trusts all installed COM Add-ins provided that you access the outlook objects through the Outlook application object (ThisApplication)
If you create a new instance then calls are restricted


Use ThisApplication instead of creating a new instance of an Application object


When Outlook is used with Exchange Server administrators can specify that all VSTO add-ins be trusted because they can specify that the AddinLoader.dll be trusted.


If macro security is set to VeryHigh or High then the add-in must be signed with a certificate
The AddinLoader.dll that shipped with VSTO was not signed, but installing VSTO 2005 SE will replace it with a signed version.



VSTO Add-ins (Outlook specific)

Visual Studio 2005 introduced the first VSTO type add-in which was only available for Outlook 2003.
This add-in model allowed Microsoft to get some valuable feedback before modifying the add-in model slightly before releasing Visual Studio 2005 SE.
The most significant change was to remove the host item base class (that wrapped the application PIA and made the add-in version specific) and replace it with an unwrapped application PIA object as a field in the class.
It is extremely easy to migrate an old style Outlook add-in to the new Outlook VSTO model.
The original VSTO 2005 Outlook add-in projects are still available in Visual Studio versions meaning that there are 2 VSTO add-in project types for Outlook 2003.


2003 add-ins will be registered the way that Office 2003 expects and uses VSTO runtime v2 even if it is running in Office 2007.


GetVSTOObject

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.Excel.Workbook 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



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext