Starting Word *without* a reference to the OCX/DLL


New member
Jun 3, 2004
Sydney, Australia
Hi all,

I'm doing an enhancement to a contacts management system I wrote for a client in VB.Net with v1.0 of the framework. Part of the enhancement is to be able to hit a button on the contact details tab to create the start of a letter in Word (ie: with the contact's address and date at the top and a salutation).

The problem I have is that there are 100's of users of this app and while most of them have Office 2000 some of them have Office XP and some even have Office 2003. So what I want to do is somehow find out, when the user presses the "Write Lettter" button if Word is installed on their machine and if so which version, then start it up, create a new document and insert the letter text into it. Can I do any/all of this without a reference to the Word OCX in the project and if so how?

Another Q - if I include a reference to say the Word 2000 OCX in the project would Word still start up on a PC running Office XP or 2003? ie: is the OCX standalone or does it still Word 2000 to be installed locally? (I strongly suspect it's the latter.)

Hope someone can point me in the right direction because I'm really not sure how to start doing this!


OK, I found it... you can use Process.Start("winword.exe","C:\letter.doc") to start it and if it's on the computer then it shouldn't matter what version of Word they use. This can be used with any external app that you want to start from a .Net app for those that haven't seen this before.

You should use late binding. Here is an example:
Dim objWord As Object
Dim objDoc As Object
objWord = CreateObject("Word.Application")
objDoc = CreateObject("Word.Document")
objWord.Visible = True

    objDoc = objWord.Documents.Open("c:\temp\doc1.doc")
    MessageBox.Show("Document couldn't be opened")
End Try

You can also check for the version in cases where the syntax may be different for the different versions:

Dim iVersion as Integer
iVersion = objWord.Version
Select Case iVersion
    Case Is >= 10
        'syntax for versions greater than 10
    Case 9
        'syntax for version 9
End Select

Thanks so much for that... as always with .Net there seems to be 2 or more ways of doing everything. I might change my Process.Start to your code as it is probably a bit safer. I assume once I've got the object I can then also use it's methods and proerties which is what I really wanted to do from the start - so it creates a proper Word doc rather than loading a temporary text file.

Cheers for the info...