Adding reference to Office library failing: type or namespace name Word not found
Solution 1
Edit: changed so that it doesn't use the clipboard
using Microsoft.Office.Interop.Word;
public string Test(string path)
{
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
string result = doc.Content.Text.Trim();
doc.Close();
return result;
}
Solution 2
You should use Microsoft.Office.Interop.Word assembly and directive
using Microsoft.Office.Interop.Word;
Solution 3
I added reference of microsoft word object library and also wrote using Microsoft.Office.Interop.Word;
at the top. But the code didn't work. I was working with the code given in this link: http://support.microsoft.com/kb/316384
Then, I changed all the "Word" with "Microsoft.Office.Interop.Word" inside the code and it worked.
Meir
Updated on June 27, 2022Comments
-
Meir almost 2 years
I'm trying to use the sample code here:
I went to "Add Reference" dialog and added "Microsoft Word 12 library", but it doesn't appear in the Solution Explorer. I also added:
using Microsoft.Office;
I get the following error message when trying to declare a "Word" object.
Error 1: The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)
Any suggestions on how to properly reference the Word library?