Namespace Error Using Microsoft.Office.Interop.Word;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deego
    New Member
    • Apr 2012
    • 2

    Namespace Error Using Microsoft.Office.Interop.Word;

    Hi,

    I use this program to sort the images in word document. in this i try to get the input as MS Word document.

    while compiling it ends with namespace error

    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using Word = Microsoft.Office.Interop.Word;
    
    namespace WindowsFormsApplication1
    {
        class WindowsFormsApplication1
        {
            #region Constructor
            public WindowsFormsApplication1()
            {
                WordApp = new Microsoft.Office.Interop.Word.Application();
            }
            #endregion
    
            #region Fields
            private Word.Application WordApp;
            private object missing = System.Reflection.Missing.Value;
            private object yes = true;
            private object no = false;
            private Word.Document d;
            private object filename = @"C:\Data\example.doc";
            #endregion
    
            #region Methods
            public void UpdateDoc()
            {
                d = WordApp.Documents.Open(ref filename, ref missing, ref no, ref missing,
                   ref missing, ref missing, ref  missing, ref  missing, ref  missing,
                   ref  missing, ref missing, ref yes, ref  missing, ref  missing, ref  missing, ref  missing);
                List<Word.Range> ranges = new List<Microsoft.Office.Interop.Word.Range>();
                foreach (Word.InlineShape s in d.InlineShapes)
                {
                    if (s.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapePicture)
                    {
                        ranges.Add(s.Range);
                        s.Delete();
                    }
                }
                foreach (Word.Range r in ranges)
                {
                    r.InlineShapes.AddPicture(@"C:\Photo\Image.jpg", ref missing, ref missing, ref missing);
                }
                WordApp.Quit(ref yes, ref missing, ref missing);
            }
            #endregion
     }
    }
    How to resolve this?
  • RhysW
    New Member
    • Mar 2012
    • 70

    #2
    I see this got answered in your msdn version of the question, though that problem is not replicated here as you have the correct capitalising on word, though ironically that may have been the spell checker in the code poster that made you update it, fixing your code for you.

    Comment

    • adriancs
      New Member
      • Apr 2011
      • 122

      #3
      dont use Microsoft.Offic e.Interop.Word,
      use Open XML SDK 2.0

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        I suggest using Microsoft.Offic e.Interop.Word as then you're using something native in the language/framework.

        What is the exact error you're getting?

        Comment

        Working...