Solved

(Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

Posted on 2009-04-07
2
4,687 Views
Last Modified: 2013-11-26
I am trying to automate Word from a VB.net application but keep getting the error:
"Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."

I ran RegAsm to register Office.dll, Microsoft.Vbe.Interop.dll and Microsoft.Office.Interop.Word.dll successfully.

However, I continue to get this error when oWord.Visible = True attempts to execute.



Imports Word = Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices
 
Private Sub OpenWordDoc
       Dim oWord As Word.Application
        Dim wDoc As Word.Document
        Dim para1 As Word.Paragraph
        Dim strResult As String
 
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
 
        wDoc = oWord.Documents.Add
        para1 = wDoc.Content.Paragraphs.Add
        para1.Range.Text = RepairCommentsTextBox.Text
 
 
        'para1 = wDoc.Content.Paragraphs.Add()
        'para1.Range.Text = RepairCommentsTextBox.Text
        'para1.Range.InsertParagraphAfter()
 
        wDoc.CheckSpelling()
 
        strResult = Microsoft.VisualBasic.Left(wDoc.Content.Text, Len(wDoc.Content) - 1)
        If Not RepairCommentsTextBox.Text = strResult Then
            RepairCommentsTextBox.Text = strResult
        End If
End Sub

Open in new window

0
Comment
Question by:PenningtonCounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 24111414
Hello, PenningtonCounty,

I'm still using Word 2000 and VS2005, but I tried running your code with those and had no trouble. (That is, until I got to "Len(wDoc.Content)".  I had to change that to "Len(wDoc.Content.Text)" to get that statement to work.)

I suspect that there must be some problem with your reference to the Word Object Library.  Have you checked this reference to make sure that it is consistent with Word 2003?

Also, I'm not familiar with the effects of the statement:

     Imports Word = Microsoft.Office.Interop.Word

but for me this statement seems to be unnecessary and generates a warning.  The code works for me both with the statement in place and also if it is commented out.  But perhaps in VS2008 and Word2003 this is causing some interference.  What happens if you remove it?

Cheers,
Randy




0
 

Author Closing Comment

by:PenningtonCounty
ID: 31567736
You did point out a problem that I had not gotten to just yet. The problem causing the error was solved by removing a conflicting Interop assembly. The following link was helpful in getting to the problem: http://msdn.microsoft.com/en-us/library/aa159923(office.11).aspx
that plus advice from a Word Automation Expert.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question