none
Word.Interop 2003/2007 RRS feed

  • Question

  • Hi, I have developed an app in vs 2010 visual basic .NET 4.0. Part of the app requires a word document to be created and displayed. The development machine has word 2010 loaded.  All works fine when installed on a machine with word 2007 - 2010 installed but fails with an error message 'unable to cast com etc' on a machine that has word 2003 loaded. The 2007 Interop is listed as a

    pre-requisite and the properties set to embed.  How do I cater for word 2003,2007,2010 in my oneclick publish?

     

    Any help greatly appreciated

    Peter

     

    Thursday, August 4, 2011 12:57 PM

Answers

  • Hi Peter,

    Try the following two workarounds to see if they can fix your issue.

    1.  Using: 

    oWord = CType(CreateObject("Word.Application"), _
            Microsoft.Office.Interop.Word.Application)
    

    2. Using: 

    oWord = New Word.Application
    

    I look forward to hearing of you.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 8, 2011 8:55 AM
    Moderator

All replies

  • AFAIK know Peter you cannot create an Office 2003 app using VS2010, you will have to port the app's code over to VS2005 or VS2008 and recompile on a development machine that contains Office 2003.
    Kind Regards, Rich ... http://greatcirclelearning.com
    Thursday, August 4, 2011 1:37 PM
  • Hi Peter

    If you're embedding the interop, then theoretically your code should/could run all the way back to Office 97. BUT that will depend on a couple of things. Which programming language are you using? My guess would be C#...

    Can you isolate the line(s) of code where it's failing and show us that, with some context?

    Also, please post the full, complete and exact error message. What you've given us isn't really helpful.


    Cindy Meister, VSTO/Word MVP
    Thursday, August 4, 2011 3:01 PM
    Moderator
  • Hi Cindy - Thanks for the prompt reply - Language is VB - will get you a bit more detail asap (I don't have Word 2003 on the dev machine so can't reproduce the error at the moment here) so will have to get the details from the clients machine.

     

    Regards

    Peter

     

    Thursday, August 4, 2011 4:48 PM
  • Hi Rich - Thanks for the reply. I've read that before but have trouble believing things could be so clumsy. Will let you know if I find a more elegant solution.

     

    Regards

    Peter

     

    Thursday, August 4, 2011 4:50 PM
  • Hi Peter

    One other thing: what kind of app is this? I got the impression WinForms, but if it's VSTO you need to read

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ea8c14e0-f0c5-4e4e-abe5-cb2005f02402#bdad0ca0-753c-4f99-985f-c02eb9153cb8


    Cindy Meister, VSTO/Word MVP
    Friday, August 5, 2011 6:44 AM
    Moderator
  • Hi Cindy - Yes its WinForms. Here's the error message:

    Unable to cast com of type 'System_ComObject' to interface type
    'Microsoft.Office.Interop.Word.Application'. This operation failed
    because the QuerInterface call on the COM component for the
    interace with ID'(00020970-0000-0000-C000-000000000046)'  failed
    due to the following error: Library not registered (Exception from HRESULT:
    0x8002801D (TYPE_E_LIBNOTREGISTERED)).

    Here's the line of code that causes the error:

    oWord = CreateObject("Word.Application")

    Hers' the start of the module:

                Dim oWord As Word.Application
                Dim oDoc As Word.Document
                Dim lPageNumber As Long = 0
                'Create a word object
                oWord = CreateObject("Word.Application")
                oDoc = oWord.Documents.Add
                oDoc.TrackFormatting = False

    'Heres the imports:

    Imports Word = Microsoft.Office.Interop.Word

    'Heres the Reference

    Microsoft.Office.Interop.Word

    Heres the Reference Properties

    Name: Microsoft.Office.Interop.Word

    Copy Local: False

    Culture

    Description

    Embed Interop Types: True

    File Type: Assembly

    Identity: Microsoft.Office.Interop.Word

    Path: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Word.dll

    Resolved: True

    Runtime Version: v2.0.50727

    Specific Version: True

    Strong Name: True

    Version: 14.0.0.0

    'Heres the one publish prerequisites

    Microsoft Office 2007 Primary Interop Assemblies

     

     

    Its a fairly straight forward document - some of the details are taken

    from a sql database to form a 'cover sheet' i.e Company Name, Document Classification (for headers and footers) and

    a company logo.

    The main body of the text is a mixture of hard coded text and text from a database.

    Just to recap: Dev machine has word 2010 loaded: Dev Environment VS2010 Professional: Winforms: Visual Basic:

    Works fine when installed on machines with

    2007 and 2010 but not 2003.

     

    Regards

    Peter

    p.s This is my first project creating word documents so be gentle!!

     

     

     

     

     

     

     

     

    Friday, August 5, 2011 10:46 AM
  • Hi Peter,

    Try the following two workarounds to see if they can fix your issue.

    1.  Using: 

    oWord = CType(CreateObject("Word.Application"), _
            Microsoft.Office.Interop.Word.Application)
    

    2. Using: 

    oWord = New Word.Application
    

    I look forward to hearing of you.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 8, 2011 8:55 AM
    Moderator
  • Hi Calvin - Thanks for the reply - will give them a try and get back to you.

     

    Regards

    Peter

     

    Wednesday, August 10, 2011 4:48 PM