61

I had developed a system that deals with excel sheets in 2006 using MS VS 2005. Now, I can not use the same reference with MS VS 2012.

var app = new Microsoft.Office.Interop.Excel.Application();
Workbooks wbs = app.Workbooks;
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Moe_Al
  • 621
  • 1
  • 5
  • 5
  • Doesn't VS2012 have Office projects? You can't use those? – Jeremy Holovacs Mar 08 '13 at 02:53
  • 1
    I got the same error when trying to build the DEMO project from Microsoft. Here endeth my attempt to develop an excel add-in. There's plenty of other projects I can be working on rather that messing around with something where even "Hello World" doesn't work. – Paul McCarthy Jan 15 '21 at 00:14

7 Answers7

108

Use NuGet (VS 2013+):

The easiest way in any recent version of Visual Studio is to just use the NuGet package manager. (Even VS2013, with the NuGet Package Manager for Visual Studio 2013 extension.)

Right-click on "References" and choose "Manage NuGet Packages...", then just search for Excel.

enter image description here


VS 2012:

Older versions of VS didn't have access to NuGet.

  • Right-click on "References" and select "Add Reference".
  • Select "Extensions" on the left.
  • Look for Microsoft.Office.Interop.Excel.
    (Note that you can just type "excel" into the search box in the upper-right corner.)

VS2012/2013 References


VS 2008 / 2010:

  • Right-click on "References" and select "Add Reference".
  • Select the ".NET" tab.
  • Look for Microsoft.Office.Interop.Excel.

VS 2010 References

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
  • 1
    When we changed from VS08 to VS12 we also have some trouble with this dll. After updating it to the dll-version 14.0. (like in the screenshot) all works fine. – Micha Mar 08 '13 at 08:05
  • I am working with VS2010 - due to firm policy - I cannot use VS2012. Where can I find the "Extensions" in the reference manager? Is it a feature only available in VS2012? If the extensions are not available in VS2010, how can I add the reference? I can't find it in the .NET assemblies listing nor in the Office directory. – Matt Sep 24 '13 at 12:35
  • 5
    What if i have VS2013 Express and i does not have an Microsoft.Office Namespace in Extension nor Framework list ? :P – Muflix Apr 20 '15 at 08:32
43

You can also try installing it in Visual Studio via Package Manager.

Run Install-Package Microsoft.Office.Interop.Excel in the Package Console. This will automatically add it as a project reference.

Use is like this:

Using Excel=Microsoft.Office.Interop.Excel;
MJH
  • 2,301
  • 7
  • 18
  • 20
CYCLONE
  • 541
  • 4
  • 5
21

If you have VS 2013 Express and you cant find Microsoft.Office namespace, try this ('Microsoft Excel 12.0 Object Library' if you want to use Office 2007)

enter image description here

Muflix
  • 6,192
  • 17
  • 77
  • 153
  • After a couple of hours searching I finally found this that sorted out why I couldn't find Microsoft.Office after adding via Nuget Package Manager and via Package Manager Console. Interop added successfully but I still couldn't add the reference!!! Extremely frustrating. VS2019. Thank you. – Alan Oct 22 '19 at 11:10
6

Building off of Mulfix's answer, if you have Visual Studio Community 2015, try Add Reference... -> COM -> Type Libraries -> 'Microsoft Excel 15.0 Object Library'.

2

Instead of early binding the reference, there's an open source project called NetOffice that abstracts this from your project, making life much easier. That way you don't have to rely on your users having a specific version of Office installed.

NetOffice Codeplex site.

LawMan
  • 3,469
  • 1
  • 29
  • 32
1

You have to check which version of Excel you are targeting?

If you are targeting Excel 2010 use version 14 (as per Grant's screenshot answer), Excel 2007 use version 12 . You can not support Excel 2003 using vS2012 as they do not have the correct Interop dll installed.

mas_oz2k1
  • 2,851
  • 3
  • 34
  • 41
1

Go to Visual Studio Installer under Individual Components and click 'Office Developer Tools for Visual Studio. This solved it for me after lots of headaches.

Go to Visual Studio Installer under Individual Components and click 'Office Developer Tools for Visual Studio'

Dan
  • 174
  • 1
  • 2
  • 11