How do I open Word Documents from VB.net

Irish

New member
Joined
May 11, 2006
Messages
3
Programming Experience
1-3
I have seen many answers to this among these threads but I guess I have a more basic question. As I try to use example codes, I find that I cannot get them to work as I do not have a proper reference (I think) to Word.

How do I make sure that I have a Word reference in my project so that I may use the example code? I am a relative novice at VB.net

Thanks
 
You add a reference by right-clicking the project in the Solution Explorer and selecting Add Reference. There are other ways too but they all amount to the same thing. You then select the COM tab and scroll down to Microsoft Word X Object Library. If you're using Word 2003 then X will be 11.0. Select it and press OK. That gives you access to the Word object model in your project, but you'd still have to qualify everything fully. You should import and alias the Word namespace so you can use it easily in your code. Place this line at the top of each file in which you want to access Word:
VB.NET:
Imports Word = Microsoft.Office.Interop.Word
This imports the namespace and creates an alias for it, so instead of having to refer to Microsoft.Office.Interop.Word.Application you can just refer to Word.Application.

Note also that adding a reference to Word to your project ties you to that version. If a user installs your app on a system that has an older version of Word then they will not be able to use it. To be able to use any version of Word is a lot more trouble. You have to load the DLL manualy and use late-binding to create your objects.
 
Thank you but I have another issue.

I added Word 11 as suggested but I cannot get the code in as suggested. What I see is an option as follows:

Imports Word = Microsoft.Office.Core

The .Interop.Word option is not available. Can you tell what I need to do from here?

Irish:confused:
 
If you only have access to the Microsoft.Office.Core namespace then you've added a reference to the Microsoft Office 11.0 Object Library, not the Microsoft Word 11.0 Object Library.
 
Thank you. I thought that I had added the Word reference before I sent this message but I'll check. If I had already added a reference to Office 11, would that create a problem for adding Word 11? Also, if I want to delete a reference, How do I find it and delete it?Thanks, Irish
 
Back
Top