Click here to Skip to main content
13,446,191 members (37,085 online)
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 2 Nov 2004

Creating Office 2000 Solutions using .NET

, 1 Dec 2004
Rate this:
Please Sign up or sign in to vote.
This article shows you how to create Office 2000 solutions using Visual Studio .NET 2003.


Traditionally, developers have used VBA to create Office based applications. When .NET came along with all its goodies, they felt the need for creating document-centric solutions with .NET. To address this need, Microsoft released Visual Studio Tools for Microsoft Office (VSTO), an add-on to Visual Studio .NET 2003 to create managed applications with Word 2003 or Excel 2003.

Visual Studio Tools for Office 2003 (VSTO) is a great tool to build Office solutions in .NET. Unfortunately, Office 2000 users cannot use this tool. This article is an attempt to fill that void. It shows you how to build Office 2000 solutions using Visual Studio .NET 2003. I have tried to keep the code as close as possible to VSTO 2003 so that you can easily migrate to Office 2003.

Getting Started

I will walk you through the process of creating a simple Word application using Visual Basic .NET. We are going to build an application consisting of a Windows Form which accepts user data and this data displayed on the Word document.

Fire up Visual Studio .NET, use the File | New | Project menu item, and select Class Library project template as shown below:

Use Project| Add References menu. Chose the COM tab and add a reference to Microsoft Word 9.0 object library.

Imports Word
Public Class OfficeCodeBehind
    Friend WithEvents ThisDocument As Word.Document
    Friend WithEvents ThisApplication As Word.Application

#Region "Initialization code"
    ' Default constructor.
    Public Sub New()
    End Sub
    Public Sub Startup(ByVal application As Object, ByVal document As Object)
        ThisApplication = CType(application, Word.Application)
        ThisDocument = CType(document, Word.Document)
    End Sub
    Public Sub Shutdown()
        ThisApplication = Nothing
        ThisDocument = Nothing
    End Sub
    Private Sub ThisApplication_DocumentOpen(ByVal Doc As Word.Document) 
            Handles ThisApplication.DocumentOpen
        MsgBox("Application event Document open")
    End Sub

    Private Sub ThisDocument_New() Handles ThisDocument.New
        MsgBox("inside Document new managed code")
    End Sub
#End Region

End Class

Create a class called OfficeCodeBehind. Create variable declarations for Application (ThisApplication) and main document (ThisDocument) objects.

Create initialization code which consists of routines Startup and Shutdown. The Startup routine is called to initialize ThisApplication and ThisDocument variables when the user opens a Word Document, and ShutDown routine is called when user closes the Word document to perform cleanup. In addition, create event handlers for basic events and a routine which writes string to Word.

Create a Windows Form which calls WriteStringToWordDocument routine of OfficeCodeBehind class to write text to Word.

Fire up Word. Use the Tools | Macro menu item and select Visual Basic Editor. Add a reference to WordTest1.tlb file by selecting Tools|References and clicking on the Browse button as shown below:

Dim app As New WordTest1.OfficeCodeBehind

Private Sub Document_Close()
End Sub

Private Sub Document_Open()
  app.Startup Me.Application, Me
End Sub

Add the above code in Visual Basic editor in ThisDocument.

The above code is the glue which connects the Word Document to the .NET class library we created. When the Word document is opened, it fires the Document_Open event which in turn calls the StartUp method of OfficeCodeBehind. It passes to Startup a reference to the Application (Word.Application) and a reference to the Document (Word.Document). The Startup method copies this information into local variables and hooks up event handling.

The Shutdown method is called when the document closes to perform any cleanup.

Creating Office Projects using Word and Excel Project Templates

Note: Please read the instructions in ProjectTemplateSetup.rtf to setup Project Templates before reading any further.

Fire up Visual Studio .NET. Use the File | New | Project menu item, and select Word Document project template as shown below:

'Called when the document is opened
Private Sub ThisDocument_Open() Handles ThisDocument.Open
    MsgBox("Document Open from Managed code")
End Sub

Add the above code in the Code Editor. Build the project. Follow the same steps outlined for the Class Library project above to hook up the Word Document to the Word Project we created in .NET.


  • Added Word and Excel Project Templates on Nov 20 2004.
  • Created a Setup package to install Project Templates on Dec 1 2004.


I highly recommend the articles below for Office development using .NET:

Future enhancements and feedback

I am planning to do the following enhancements when time permits:

  • Create a Word Add-in (which mimics VSTO 2003 loader OTKLOADR.DLL) to automatically load the DLL which is set in Word document's Custom properties.
  • Create C# version of the project.

Feel free to email me your suggestions and comments. I would like to make improvements based on your feedback and your high ratings :).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
Sriram works as Senior Technical Specialist at Infosys's Microsoft Technology Center.

He has been working on ASP.NET,VB.NET,C#,ASP and SQL Server for past 7 years. He loves to churn out innovative ideas.

During his freetime,you may find him hiking, humming a song in his karaoke or listening to inspiring music. You can reach him at

You may also be interested in...


Comments and Discussions

QuestionUse VS 2005, file assembly not found Pin
dewacp1-Dec-07 22:01
memberdewacp1-Dec-07 22:01 
QuestionHow To Use It In VS2005? Pin
ari.sty28-May-07 2:58
memberari.sty28-May-07 2:58 
AnswerRe: How To Use It In VS2005? Pin
srirambalaji13-Nov-07 3:49
membersrirambalaji13-Nov-07 3:49 
Generalusing : .net win32/api hooking and this concept Pin
theGhost_k814-Jun-06 0:30
membertheGhost_k814-Jun-06 0:30 
Generalusing -> .net win32/api hooking and this concept Pin
theGhost_k814-Jun-06 0:30
membertheGhost_k814-Jun-06 0:30 
Questionerror Pin
dave1823-May-06 6:22
memberdave1823-May-06 6:22 
Generaloffice 2000 project deployement Pin
fatih isikhan2-Apr-06 20:46
memberfatih isikhan2-Apr-06 20:46 
Questionbring the program and the template to a different computer Pin
Mapsoft131-Jan-06 4:16
memberMapsoft131-Jan-06 4:16 
AnswerRe: bring the program and the template to a different computer Pin
srirambalaji31-Jan-06 6:23
membersrirambalaji31-Jan-06 6:23 
QuestionRe: bring the program and the template to a different computer Pin
Mapsoft131-Jan-06 9:41
memberMapsoft131-Jan-06 9:41 
AnswerRe: bring the program and the template to a different computer Pin
srirambalaji1-Feb-06 20:01
membersrirambalaji1-Feb-06 20:01 
GeneralRe: bring the program and the template to a different computer Pin
Mapsoft11-Feb-06 23:43
memberMapsoft11-Feb-06 23:43 
GeneralAccess to .Net from word 2000 via a WLL Pin
Bill Brotherton15-Aug-05 19:25
sussBill Brotherton15-Aug-05 19:25 
Questiontlb file? Pin
Jeff T.5-Jan-05 5:08
memberJeff T.5-Jan-05 5:08 
AnswerRe: tlb file? Pin
srirambalaji7-Jan-05 10:18
membersrirambalaji7-Jan-05 10:18 
GeneralProject setup Pin
n4nilesh22-Nov-04 6:11
membern4nilesh22-Nov-04 6:11 
GeneralRe: Project setup Pin
srirambalaji23-Nov-04 8:42
membersrirambalaji23-Nov-04 8:42 
GeneralRe: Project setup Pin
n4nilesh24-Nov-04 2:34
membern4nilesh24-Nov-04 2:34 
GeneralRe: Project setup Pin
srirambalaji24-Nov-04 3:08
membersrirambalaji24-Nov-04 3:08 
GeneralRe: Project setup Pin
n4nilesh24-Nov-04 6:10
membern4nilesh24-Nov-04 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180314.2 | Last Updated 1 Dec 2004
Article Copyright 2004 by srirambalaji
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid