Declaring a Word Document?

So I'm trying to open a word document in my program so I can modify it, but I'm having trouble setting it up.

I added a reference to the Word 11.0 Object Library and then added the following code:

    Friend WithEvents oWord As New Word.Application
    Friend WithEvents oDoc As Word.Document

But when I hover over Word.Application and Word.Document it tells me "Type 'Word.Application' is not defined.

What am i missing?
brassmonkeyboyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
that should work.

if you look in the solution explorer, under references do you see the word reference ?
sj_hicksCommented:
You'll need to add a reference to the Microsoft.Office.Interop namespace:

Imports Microsoft.Office.Interop

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sj_hicksCommented:
You should also install the Word PIAs from the Office 2003 setup.
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

sj_hicksCommented:
Here's an MS example:  http://support.microsoft.com/kb/316383/EN-US/
(Sorry for the multiple posts - having bad day)
planoczCommented:
Use this in a Module...

Sample

'MODULE

    Public objWord As Word.Application 'is for Word App.


          If objWord Is Nothing Then
            objWord = CreateObject("Word.Application")
        End If

          With objWord
                 .Application.Documents.Open(sDOC)
                 .Visible = True
                 .ActiveDocument.Close()
                .Application.Quit()
            End With

        objWord = Nothing
brassmonkeyboyAuthor Commented:
Ron, I DO see the Microsoft.Office.Core reference.

SJ Hicks, I added the "Imports" statement and it gives me one more error on top of the other two I was already getting:  "'Imports' statements must precede any declarations." This persists no matter where I put it in the code.

I have installed everything on the Office 2003 CD related to automation and VB, but I saw nothing called PIA...

Planocz, will that solve my problem?  I don't see how that fixes the fact that Word.Application is not defined...

Thanks for bearing with me...
brassmonkeyboyAuthor Commented:
Okay, I went back through the references list after installing everything on the Office 2003 CD and found a Word Object 11.0 Library Reference.  When I have this installed, "Imports Microsoft.Office.Interop.Word" works fine.  But it doesn't fix the other two delcarations...

David
brassmonkeyboyAuthor Commented:
Also, Planocz, I'm new enough that I don't even know what a module is...so maybe THAT's why I don't understand how your code can help me...
brassmonkeyboyAuthor Commented:
AH HA!  If I change

    Friend WithEvents oWord As New Word.Application
    Friend WithEvents oDoc As Word.Document

to
    Friend WithEvents oWord As New Microsoft.Office.Interop.Word.Application
    Friend WithEvents oDoc As Microsoft.Office.Interop.Word.Document

Everything seems to be okay!

Why might that be?  (I'll give each of you points for your help that put me on my way to figuring this out...)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.