0

I am trying to use the Microsoft.Office.Interop.xxxxxxx namespace but Visual Studio 2010 is not providing an option for "interop". I have the PIA's installed for office12 and office14, I have included them in the 'References' in the Solution Explorer, but it is not working.

The code I am trying to call the namespace with is:

    using Excel = Microsoft.Office...;

After "Office.", I am only given the option for "Core". So it would look like this

    using Excel = Microsoft.Office.Core;

This matches the reference that was imported...but using this namespace does not seem to be useful.

My question is how do I get the Microsoft.Office.Interop option to be accepted and display in intellisense?

Example:

    using Excel = Microsoft.Office.Interop.Excel;

Error message being received for 'Interop'= "The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?)

The assembly that I loaded in the Solution Explorer is "Microsoft Office 14.0 Object Library" TypeLib Version 2.5. The assembly path = "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSO.DLL

Thanks for any suggestions!

Chris
  • 934
  • 1
  • 17
  • 38

1 Answers1

1

You didn't pick the correct reference. Use "Microsoft Excel 14.0 Object Library" instead.

Note that VS2010 supports the Embed Interop Types property for an assembly reference. You really want to use that for an Office app, no PIA required. It is automatically set to True.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Hans, thank you for the response. I found the reference Microsoft.Office.Interop.Excel under >Add References > .NET, instead of COM and it is working. – Chris Jul 14 '12 at 21:00
  • I actually could not find that one in the COM tab. Do you know of a source off had that can explain the "Embedded Interop Types" you mentioned? – Chris Jul 14 '12 at 21:10
  • You've got another problem. If you don't see it listed in the COM tab by the name I gave you then you don't have Office installed on the machine and you cannot test your code. Just the PIA isn't good enough. You'll need to fix that. – Hans Passant Jul 14 '12 at 21:11
  • 1
    The "Embed Interop Types" is a set and forget it kind of setting. The only thing that can go wrong is trying to create an instance of a COM class whose name ends with "Class", which is just a mistake you can fix by omitting Class from the name. The underlying technology is pretty deep and takes you on a rollercoaster ride on type identity in .NET. There's a channel9 video about it with the two guys that made it work. Wholesome geeky stuff and the kind of feature that makes .NET so doggone awesome: http://channel9.msdn.com/Blogs/Charles/Raja-Krishnaswamy-and-Jesse-Kaplan-CLR-4-Inside-No-PIA – Hans Passant Jul 14 '12 at 21:29
  • Hans, I don't have enough rep. yet to give you a bump but I do appreciate your time and response. – Chris Jul 21 '12 at 12:19