none
C#NET2008 Using Microsoft WORD 2003 RRS feed

  • Question

  • Hullo Good Friends,

    I do need your help. Please help me.

     

    I am encountering a very puzzling problems using Microsoft Office WORD 2003 on C#NET2008 Window Application.

    I am trying to export Customer Invoice Transactions to NonTemplate WORD 2003 Document and it's not working

     

     

     

    using System;

    using System.Data.SqlClient;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.IO;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    using Microsoft.Office;

    using Microsoft.Office.Interop.Word;

     

    Error messages generated:

    Error     1  The type name 'Application' does not exist in the type 'Microsoft.Office.Interop.Word.Words'        

    Error     2  The type name 'Document' does not exist in the type 'Microsoft.Office.Interop.Word.Words'         

    Error     3  The type name 'Table' does not exist in the type 'Microsoft.Office.Interop.Word.Words'    

    Error     4  The type name 'Range' does not exist in the type 'Microsoft.Office.Interop.Word.Words'

    Error    5  The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)

     

    namespace CSharpNet2008UseWORD2003

    {

        public partial class FrmWORDReport : Form

        {

            //---declare and instantiate WORD Objects     

            private Words.Application  objWord;

            private Words.Document  objDoc;

            private Words.Table  objTable;

            private Words.Range objTableRange;

        }

    }

     

    I have tried using these coding and it’s not working either:

            private Word.Application  objWord;

            private Word.Document  objDoc;

            private Word.Table  objTable;

            private Word.Range objTableRange;

     

    private void btnWord_Click(object sender, EventArgs e)

     {

       objWord = new Word.Application;     // < -- not working either

       objWord.Visible = true;             // < -- not working either

       objdblPos = objWord.InchesToPoint(7);  // < -- not working either

     }

     


    Thank you very Much, Have a Good Day. Cheers, Lennie
    • Moved by Leo Liu - MSFT Monday, August 29, 2011 6:11 AM Moved for better support. (From:Visual C# General)
    Friday, August 26, 2011 4:43 AM

Answers

  • Hi Tee Leong,

    I tested the code on my side and it works well. Try to test the code again on your side:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Word = Microsoft.Office.Interop.Word;
    
    namespace FrmWordReport
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
        private Word.Application objWord;
    
        private Word.Document objDoc;
    
        private Word.Table objTable;
    
        private Word.Range objTableRange; 
    
        private void button1_Click(object sender, EventArgs e)
        {
          objWord = new Word.Application();   // < -- not working either
           
          objWord.Visible = true;       // < -- not working either
           
          float objdblPos = objWord.InchesToPoints(7); // < -- not working either
    
        }
      }
    }
    
    

    I found your code is wrong with the statement: objWord = new Word.Application; // < -- not working either

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [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.

    • Marked as answer by Bruce Song Wednesday, September 7, 2011 8:22 AM
    Tuesday, August 30, 2011 7:06 AM

All replies

  • 1. Have you added a new Reference in the references? You can add it in: In solution explorer select "References, righ click on in and select Add reference. Then form the 1st tab scroll down and choose Microsoft.Office.Interop.Word

    2. Try to specify the full path of the classes.

    If 1st point is achived sucsessfully, this should work:

    using System;
    using Microsoft.Office.Interop.Word;
    
    class Program
    {
      static void Main()
      {
    	// Open a doc file.
    	Application application = new Application();
    	Document document = application.Documents.Open("C:\\word.doc"); //an on with the code...
    

    btw, which version of the references do you have of the Word? I have 10 and 11, and using 10.


    Mitja

    Friday, August 26, 2011 4:49 AM
  • HUllo Mitja Bonca,

    If you view my original posting
    I am using

    using Microsoft.Office.Interop.Word;

    And the Version reference of WORD is Version 11

     

     

    Cheers

    Tee Leong


    Thank you very Much, Have a Good Day. Cheers, Lennie
    Friday, August 26, 2011 6:54 AM
  • Hi Tee

    I guess your problem is version of Word reference. try older version than 11. or if it is possible for you change your document into 2007 or 2010 MS word.

    Friday, August 26, 2011 8:12 AM
  • Hi Raman,

    Thank you very much for trying to help me.

    Regarding the Microsoft WORD 2003 version, The company that I work for, this version 2003 is the standard WORD version throughout the whole company.  I have to follow the rules and requirements.

    Cheers,

    Tee Leong


    Thank you very Much, Have a Good Day. Cheers, Lennie
    Saturday, August 27, 2011 4:48 AM
  • Hi Tee Leong,

    I tested the code on my side and it works well. Try to test the code again on your side:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Word = Microsoft.Office.Interop.Word;
    
    namespace FrmWordReport
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
        private Word.Application objWord;
    
        private Word.Document objDoc;
    
        private Word.Table objTable;
    
        private Word.Range objTableRange; 
    
        private void button1_Click(object sender, EventArgs e)
        {
          objWord = new Word.Application();   // < -- not working either
           
          objWord.Visible = true;       // < -- not working either
           
          float objdblPos = objWord.InchesToPoints(7); // < -- not working either
    
        }
      }
    }
    
    

    I found your code is wrong with the statement: objWord = new Word.Application; // < -- not working either

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [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.

    • Marked as answer by Bruce Song Wednesday, September 7, 2011 8:22 AM
    Tuesday, August 30, 2011 7:06 AM