none
Using MS Word with Framework 4.0 RRS feed

  • Question

  • I have code generated for an early Net Framework.
    It includes a reference to:
    Microsoft Word 12.0 Object Library
    and the code:
    Imports Microsoft.Office.Interop
    .
    .
    .
    Dim colSpellErrors As Word.ProofreadingErrors
    I've recently read that there is another way to 
    include Word in a VB.Net application.
    And I believe there must be an example on the Internet
    because when I search I get thousands of hits but can't 
    find one that tells me how to change my code.
    I believe I need to remove the above mentioned reference
    and maybe the Imports statement, and then do what??
    Add: Option Infer On?
    Can you tell me how to convert my code to use the 
    Framework 4.0 features?

    Wednesday, October 17, 2012 10:42 PM

Answers

  • Hi Joe,

    You've mentioned that

    I've recently read that there is another way to include Word in a VB.Net application.

    Is it a webpage or book? It will be nice if you could show me it.

    I always write like the below

    Imports Word = Microsoft.Office.Interop.Word

    After .netframework 4.0 , if you want to open a word document, you can simply use

    wdApp.Documents.Open(fileName)

    which means for the optional parameters in this method you'll have no need to type a lot of Type.Missing. The same goes for other methods.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Hirendra Sisodiya Thursday, October 18, 2012 7:18 AM
    • Unproposed as answer by Joe Sulla Thursday, October 18, 2012 3:46 PM
    • Marked as answer by Joe Sulla Thursday, October 18, 2012 3:58 PM
    Thursday, October 18, 2012 6:56 AM
    Moderator
  • Hi Joe,

    Thank you for your last reply.

    >With Framework 4.0 do I need to add a reference to the project?
    For this question my answer is Yes that means you'll need to add a reference.

    >If so, how to I compensate for the fact that different machines may have different versions on Word on them?
    For this question I've figured out this page for you.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Joe Sulla Friday, October 19, 2012 12:10 AM
    Thursday, October 18, 2012 11:38 PM
    Moderator

All replies

  • Hi Joe,

    You've mentioned that

    I've recently read that there is another way to include Word in a VB.Net application.

    Is it a webpage or book? It will be nice if you could show me it.

    I always write like the below

    Imports Word = Microsoft.Office.Interop.Word

    After .netframework 4.0 , if you want to open a word document, you can simply use

    wdApp.Documents.Open(fileName)

    which means for the optional parameters in this method you'll have no need to type a lot of Type.Missing. The same goes for other methods.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Hirendra Sisodiya Thursday, October 18, 2012 7:18 AM
    • Unproposed as answer by Joe Sulla Thursday, October 18, 2012 3:46 PM
    • Marked as answer by Joe Sulla Thursday, October 18, 2012 3:58 PM
    Thursday, October 18, 2012 6:56 AM
    Moderator
  • I did not mean to unpropose - I was replying and must have click the wrong thing. That reply is also gone!

    Anyway, do I need to reference anything. I tried it with a Microsoft Word 12.0 Object Library and without and can't get my statement to not have Undefined errors.

    I was hoping I did not need to have a reference unless new versions of word still have the 12.0 Object Library. Do they?

    How would you write the following statements?

    Imports Microsoft.Office.Interop
    ...
    Dim colSpellErrors As ProofreadingErrors
    Dim colSuggestions As Word.SpellingSuggestions
         
    Dim wordApp As New Word.Application
    Dim wordDoc As New Word.wdApp.Documents


    • Edited by Joe Sulla Thursday, October 18, 2012 3:59 PM
    Thursday, October 18, 2012 3:58 PM
  • Hi Joe,

    Thank you for your last reply.

    The Microsoft.Office.Interop version you reference should be correspond to the Office version of your machine.

    • Office 2003 ----- 11.0.0.0
    • Office 2007 ----- 12.0.0.0
    • Office 2010 ----- 14.0.0.0

    The last line of your code should be adapted into

    Dim wordDoc As New Word.Document  'It mean that the variable wordDoc is a Word.Document variable

    Hope it helps. If you still have some other confusions, please feel free to let me know.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, October 18, 2012 4:15 PM
    Moderator
  • Maybe I should start at the beginning.

    With Framework 4.0 do I need to add a reference to the project?

    If so, how to I compensate for the fact that different machines may have different versions on Word on them?

    Thanks

    Thursday, October 18, 2012 7:31 PM
  • Hi Joe,

    Thank you for your last reply.

    >With Framework 4.0 do I need to add a reference to the project?
    For this question my answer is Yes that means you'll need to add a reference.

    >If so, how to I compensate for the fact that different machines may have different versions on Word on them?
    For this question I've figured out this page for you.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Joe Sulla Friday, October 19, 2012 12:10 AM
    Thursday, October 18, 2012 11:38 PM
    Moderator