The common
way to develop new functionality or custom functionality to outlook, word, excel
is to develop COM addins. There are many different different technologies for
making these types of addin such as Visual Basic 6.0, Delphi, C++ and .net etc.
If we talk ABOUT .NET Then there are two main ways
for develop addin:
With
thew help of IDTExtensibility interface and other.
With
the help VSTO(Visual studio tools for office) technology.
VSTO
supports both languages VB.net and C# and office 2003 and later version.
This
article demonstrate that how to make wordaddin for word 2010 by using vsto 2010.
Objective:
Showing Welcome message on word application start
up
Start project:
Start vsto project File--> New project-->installed
Template -->Visual basic--> office-->2010 Select Word 2010 add-in

Visual studio automatically
generate thisAddin.vb class( thisaddin.vb in vb.net and thisaddin.cs in C#.). we
can see this class in our project. We can use this class to perform various task
such as customizing the user interface of the word application , accessing
object model of office host application(ih this project microsoft is the host
application) etc. this type of addin is also called by 'application label addin'.

There
are two default event handlers in this class one is ThisAddin_Startup and other is ThisAddin_ShutDown.
Vsto addin use
object model of host application, means if we are working for outlook addin in
vsto then addin will use outlook object model or if we are working in word addin
project then addin application will use word object model so our addin
application will use Word Object Model.
So right now
I am telling about some important things about word
object model
Word object model
consists of classes and interfaces that are provided
in the primary interop assembly for Word, and are defined in the
Microsoft,office,Interop.Word namespace.
The
following sections briefly describe the top-level objects of word object model
and how they interact with each other. These objects include the following five:
-
Application object
-
Document object
-
Selection object
-
Range object
-
Bookmark object
Application
Object
The
Application object represents the Word application, and it is root object of
other objects. We can use its properties and methods to control the Word
application.
Document
Object
Document object represents a document and all of its contents. When you open a
document or create a new document, you create a new
Microsoft,office,Interop.Word.document object, which is added to the Documents
collection of the Application object. The document that has the focus is called
the active document. It is represented by the ActiveDocument property of the
Application object. Selection Object
The
Selection object represents the current selected area. When you perform an
operation in the Word user interface, such as bolding text, you select, or
highlight the text and then apply the formatting Range Object
The
Range object represents a contiguous area in a document, and is defined by a
starting character position and an ending character position. Content Control Objects
A
Microsoft,office,Interop.Word.ContentControl provides a way for you to control
the input and presentation of text and other types of content in Word documents.
Such as richtext contentcontrol,plaintext content control…
Code:
Private Sub ThisAddIn_Startup()
Handles Me.Startup
MessageBox.Show("Welcome
to My Word Add-in")
End Sub
Private Sub ThisAddIn_Shutdown()
Handles Me.Shutdown
End Sub
Private Sub Application_NewDocument(ByVal
Doc As Microsoft.Office.Interop.Word.Document)
Handles Application.NewDocument
MessageBox.Show("This
is the new document")
End Sub
Run Addin:
Build your project and run.