Can't get Microsoft.Office.Interop reference to work

Ben Strombeck picture Ben Strombeck · Jul 24, 2013 · Viewed 92.8k times · Source

I have a C# winforms app and I am simply trying to open an Excel sheet. When I try to add a reference to Microsoft.Office.Interop, the "Office" part is red and says "Can't resolve symbol 'Office'".

When I attempt to build, the error is:

The type or namespace name 'Office' does not exist in the namespace 'Microsoft' 
    (are you missing an assembly reference?)

I have Office 2012 installed, and I think I have the Primary Interop Assemblies installed... but I'm not positive.

I know that this should be so easy, but I've been looking around for an answer to this for almost an hour and just can't figure it out. Thanks in advance!

Answer

Simon Hutchison picture Simon Hutchison · Jul 20, 2017

Use NuGet Package Manager in VS2015

  • Right click references in your visual studio project
  • Select Manage NuGet Packages
  • Type microsoft.office in the search box
  • Select Microsoft.Office.Interop.Excel
  • Click Install
  • Rebuild your solution