none
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 '{0002

    Question

  • I have a VB.net application in which I am trying to start Word and create a document in which i can use the SpellChecker. when I create the Word object i get this 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)).


    After trying all other suggestions found with respect to a search for this error I then
    remove the references to Office from my program
    I then downloaded the Office PIAs and ran register.bat to copy the PIA to the GAC and register them
    I re-added a reference to Microsoft Word 11.0 Object Library
    I added Imports Microsoft.Office.Interop.Word and Imports Microsoft.Office.Core statement to the project
    I implemented code (directly from Microsoft resources, i.e.)
            Dim oWord As New Microsoft.Office.Interop.Word.Application()  (also tried ApplicationClass())
            oWord.Visible = True

    and I continue to get the above error and really need some assistance.


    Peter W. Ottoson
    Wednesday, April 08, 2009 5:04 PM

Answers

  • Cindy,

    I followed that first link and checked my registry, Everything looked OK there. I went back into Add/Remove Programs and noticed several more Office 2007 Security updates for both Office 2003 and Visual Studio 2008. I removed all of these updates, rebuilt Office 2003 and Alleluia,


    dim strResult as string
    dim oWord as Microsoft.Office.Interop.Word.Application
    oWord = New Microsoft.Office.Interop.Word.Application
    oWord.Visible = True
    oWord.ActiveDocument.Range.InsertAfter(RepairCommentsText.Text)
    oWord.ActiveDocument.CheckSpelling()

    strResult = oWord.ActiveDocument.Range.Text

    If Not RepairCommentsTextBox.Text = strResult then
         repairCommentsTextBox.Text = strResult
    End If

    oWord.Quit(SaveChange:= False)
    oWord = Nothing


    WORKS


    Thank you so very much for all of your help in resolving this problem.


    I have one more question that I believe is within your expertise...

    Is there a way to envoke the Word SpellChecker within a textbox while the user is actively typing in it?


    Thanks Pete


    Peter W. Ottoson
    Thursday, April 09, 2009 3:22 PM
  • Hi Pete

    <<Thank you so very much for all of your help in resolving this problem.>>

    Your more than welcome :-) Thank you for taking a moment to come back and tell us what worked! As you experienced first hand, these are nasty issues and it takes some perseverance to track them down!

    <<I have one more question that I believe is within your expertise...

    Is there a way to envoke the Word SpellChecker within a textbox while the user is actively typing in it?>>

    What kind of text box? Word has three things in the UI that are called that; VBA Userforms another, and then there's the entire .NET palette that comes into play...

    If it helps: once Word is running you should be able to pass the CheckSpelling method a string, directly. But you can't get the squiggly underline in a Windows Form or Word's Spell check dialog box or anything like that.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by PeterWayne Thursday, April 09, 2009 3:44 PM
    Thursday, April 09, 2009 3:30 PM
    Moderator
  • Hi Peter

    I hope you're feeling much better, now :-)

    OK, now I see what you were looking at. And clicking the link takes me to this page. What you're looking at here is part of the .NET Framework and has nothing to do with using the Word object model or VSTO. It's available only for .NET Framework 3.0 and higher (that would be VS 2005 interim release). If you need help using that you should ask in a forum that supports Windows Forms, such as here.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by PeterWayne Wednesday, April 15, 2009 4:35 PM
    Wednesday, April 15, 2009 4:30 PM
    Moderator

All replies

  • Hi Peter

    One little piece of information you don't give is: Which version of Office is installed on your machine?

    (Please note that your question is actually off-topic in the VSTO forum. If we can solve this quickly, that's fine, but you may have to go elsewhere. See the forum's Please Read First message for more information, as well as links to other venues.)
    Cindy Meister, VSTO/Word MVP
    Wednesday, April 08, 2009 5:25 PM
    Moderator
  • Cindy,

    Sorry I omitted that information.

    I have Office 2003 installed on my machine.


    Thanks,

    Pete


    Peter W. Ottoson
    Wednesday, April 08, 2009 5:32 PM
  • Hi Pete

    Sorry I omitted that information.

    I have Office 2003 installed on my machine.


    <sigh> It couldn't have been that easy that you had a version mis-match - but I was hoping!

    Since you use VB.NET I hope you're not adverse to doing a bit of "fiddling" with Office VBA? Would you mind starting up excel and creating a new VBA modul that tests whether Office, itself, has access to the Word application? that would tell us whether the problem is with Office, or with the .NET/COM interface. And if it doesn't work you might get a more informative message. Something like this should do it:

    'Tools/References and set a Reference to the Microsoft Word application!!!
    Sub StartWord()
         Dim wdApp as Word.Application
         Set wdApp = New Word.Application
        wdApp.Visible = True
    End Sub

    If that doesn't work, try late-binding:

    Sub StartWord()
         Dim wdApp as Object
         Set wdApp = CreateObject("Word.Application")
        wdApp.Visible = True
    End Sub


    Cindy Meister, VSTO/Word MVP
    Wednesday, April 08, 2009 5:50 PM
    Moderator
  • Cindy,

    Using your first code block suggestion I get the following error:
     
           Run-time error '-2147319779 8002801d)':

          Automation error
          Library not registered

    Peter W. Ottoson
    Wednesday, April 08, 2009 6:02 PM
  • Using your first code block suggestion I get the following error:
     
           Run-time error '-2147319779 8002801d)':

          Automation error
          Library not registered

    Hi Peter

    And the second code block works?

    Try a Repair of the Office installation.

    BTW, do you (or have you ever) had any other versions of Office installed on this machine? Especially in-parallel? And more especially, was it Office 2007?

    Cindy Meister, VSTO/Word MVP
    Wednesday, April 08, 2009 6:16 PM
    Moderator
  • Cindy,

    I am not aware of anyother install/version of Office on this machine. However, when I go to Control Panel \ Add\Remove Programs, I can see that there is an Office 2007 Primary Interop Assemblies and a Security Update for Microsoft Office PoserPoint 2007 in stall last month.

    As far as the second code block working, when I first entered it I got an error but I just copy/pasted your code and it does work!!

    I just did the repair of Office 2003 as well. Do you think that I should un-install those two above mention Office 2007 items?


    Thanks

    Pete


    Peter W. Ottoson
    Wednesday, April 08, 2009 6:56 PM
  • Hi Pete

    The Office 2007 PIAs being present certainly does cause problems, although I can't recall it forcing VBA (which would never use PIAs) to have problems with the version. In any case, you do want to at least remove the Registry entry for these PIAs from the machine.  See these message threads for discussion and possible solutions

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/08f13e9d-895c-4102-b6d9-e327af8cf8c0/
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/3f12200d-f685-4bc9-bff0-d380067f515a/

    In the first discussion you'll see that just uninstalling the other set of PIAs usually doesn't resolve the issue (if it is indeed that issue) as it doesn't change the Registry entries.

    I'm not familiar with "PoserPoint", do you mean PowerPoint? You should definitely remove that if 2007 isn't on the machine. And then I'd run a repair on Office 2003 again.

    In your place, I'd probably also open up Word's VBA editor and see if coding, generally, works within Word or if Word doesn't even recognize itself. And I'd also see if I can automate Excel (same as the other VBA, except subsitute Excel.Application for Word.Application).
    Cindy Meister, VSTO/Word MVP
    Thursday, April 09, 2009 12:43 PM
    Moderator
  • Cindy,

    I followed that first link and checked my registry, Everything looked OK there. I went back into Add/Remove Programs and noticed several more Office 2007 Security updates for both Office 2003 and Visual Studio 2008. I removed all of these updates, rebuilt Office 2003 and Alleluia,


    dim strResult as string
    dim oWord as Microsoft.Office.Interop.Word.Application
    oWord = New Microsoft.Office.Interop.Word.Application
    oWord.Visible = True
    oWord.ActiveDocument.Range.InsertAfter(RepairCommentsText.Text)
    oWord.ActiveDocument.CheckSpelling()

    strResult = oWord.ActiveDocument.Range.Text

    If Not RepairCommentsTextBox.Text = strResult then
         repairCommentsTextBox.Text = strResult
    End If

    oWord.Quit(SaveChange:= False)
    oWord = Nothing


    WORKS


    Thank you so very much for all of your help in resolving this problem.


    I have one more question that I believe is within your expertise...

    Is there a way to envoke the Word SpellChecker within a textbox while the user is actively typing in it?


    Thanks Pete


    Peter W. Ottoson
    Thursday, April 09, 2009 3:22 PM
  • Hi Pete

    <<Thank you so very much for all of your help in resolving this problem.>>

    Your more than welcome :-) Thank you for taking a moment to come back and tell us what worked! As you experienced first hand, these are nasty issues and it takes some perseverance to track them down!

    <<I have one more question that I believe is within your expertise...

    Is there a way to envoke the Word SpellChecker within a textbox while the user is actively typing in it?>>

    What kind of text box? Word has three things in the UI that are called that; VBA Userforms another, and then there's the entire .NET palette that comes into play...

    If it helps: once Word is running you should be able to pass the CheckSpelling method a string, directly. But you can't get the squiggly underline in a Windows Form or Word's Spell check dialog box or anything like that.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by PeterWayne Thursday, April 09, 2009 3:44 PM
    Thursday, April 09, 2009 3:30 PM
    Moderator
  • Cindy,

    I am referring to a TextBox control within my Visual Basic .NET application. The code in my last post is located in the TextBox_Leave event coding and while this works well, it would be really cool if i could have SpellCheck interactively work with the 'active' contents of the TextBox as the user was actively typing.
    Peter W. Ottoson
    Thursday, April 09, 2009 3:47 PM

  • I am referring to a TextBox control within my Visual Basic .NET application. The code in my last post is located in the TextBox_Leave event coding and while this works well, it would be really cool if i could have SpellCheck interactively work with the 'active' contents of the TextBox as the user was actively typing.
    Hi Pete,

    I'm afraid you'd have to build your own, or find and license a third-party class. Word's spell-check UI only works within the Word application window.
    Cindy Meister, VSTO/Word MVP
    Thursday, April 09, 2009 3:55 PM
    Moderator
  • Hi Cindy,

    I found this link (http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(VS.85).aspx) that would seem to disagree, but I don't fully understand it as yet and may not even be smart enough to figure it out. I have never used PresentationFramework.

    Regardless, you have my application up and running and as far as I am concerned you are an Angel of the first order. Thank you for all of your help and I hope that you have a great day, weekend and a very Happy Easter. May God Bless.


    Most Sincerely,


    Peter
    Peter W. Ottoson
    Thursday, April 09, 2009 4:39 PM


  • I found this link (http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(VS.85).aspx) that would seem to disagree, but I don't fully understand it as yet and may not even be smart enough to figure it out. I have never used PresentationFramework.


    I'm afraid I'm a bit confused. I see nothing on the page you link to that indicates you should be able to use any kind of spell check in a .NET 3.0 WPF plain text box? Could you indicate to me which part of the article gives you that idea?
    Cindy Meister, VSTO/Word MVP
    Friday, April 10, 2009 3:27 PM
    Moderator
  • Hi Cindy,

    Sorry, but I've been out with a bad cold for the last two days.

    I'm sorry, I had so many articles open that I sent  you the wrong link

    http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase_members(VS.85).aspx

    This is the link for the TextBoxBase which has a SpellCheck member. However, my research, which is not very conclusive, hasn't shown that I can use this in my VB application.


    Thank you,

    Peter
    Peter W. Ottoson
    Wednesday, April 15, 2009 1:39 PM
  • Hi Peter

    I hope you're feeling much better, now :-)

    OK, now I see what you were looking at. And clicking the link takes me to this page. What you're looking at here is part of the .NET Framework and has nothing to do with using the Word object model or VSTO. It's available only for .NET Framework 3.0 and higher (that would be VS 2005 interim release). If you need help using that you should ask in a forum that supports Windows Forms, such as here.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by PeterWayne Wednesday, April 15, 2009 4:35 PM
    Wednesday, April 15, 2009 4:30 PM
    Moderator
  • Cindy,

    I am feeling much better :-)

    You are absolutely correct. Let's consider this issue closed and I will pursue the TextBoxBase from WPF as a totally separate issue. All of the links with in this series have contributed to the total resolution of my original problem, that being automating Word from my VB.net application.

    For those wishing to continue pursuing down this path, here is a helpful link to get them started.

    http://www.danielmoth.com/Blog/2007/10/wpf-and-windows-forms-integration.html


    I can not thank you enough for all of your help, expertise and valuable time.


    Thank you,



    Peter W. Ottoson
    Wednesday, April 15, 2009 4:44 PM