Why can't VB.NET automate Ms Word?
I'm using VB.NET and Word 97. In the VS.NET 'Add Reference' dialog, I added
the Microsoft Word 8.0 Object Library to my solution. (The TypeLib version
shows up as 8.0). I added the reference, and let the IDE create a wrapper
for it. I was able to add the lines:
Dim objWordApplication As Word.Application
Dim objDoc As Word.Document
objWordApplication = New Word.Application()
using the auto-complete feature (it recognized Word, Word.Application, and
Word.Document). However, the next line:
objDoc = objWordApplication.Documents.Add
gets a blue squiggle, with the error "The name 'Documents' is not a member
of 'Word.Application' ". My subsequent reference to objWordApplication.Selection
has the same problem.
The entire Word 97 object hierarchy shows up in the object browser under
Interop.Word_8_0, with the notable exception that both the Document object
and the Documents collection are directly under Word, rather than under Word.Application.
The only members of Application are the Dispose, Finalize, and New methods,
and the DocumentChange, Quit, and Startup events. As far as I can determine,
Word.Documents has all of its usual members (including the Add method and
the Application property).
However, when I look at the hidden members of Word.Application, all of the
many expected properties (including the Documents collection) are shown.
I'm not sure of the significance of these members being hidden -- except
that it obviously has a lot to do with whatever is wrong.
I've been successfully using the same olb file in my VB 6.0 projects.
I also tried running the original MSWORD8.olb through TLBIMP.exe, and it
produced a dll identical to the Interop.Word_8_0.dll that the 'Add Reference'
dialog had created.
Looking at the olb file with the OLE/COM Object Viewer, the Application interface
is marked as hidden, so its not so surprising that I'm having this problem.
What is surprising is that my VB 6.0 projects and everybody else doing Ms
Word automation with .NET aren't having this problem.
Can anybody tell me what is wrong here?
What a nightmare
I am having the same exact issue. I have seen numerous forums posting the same issue but there are no responses. I am starting to think it's just one of those microsoft things that's supposed to work but just doesn't..
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL