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;
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.
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.)
VS 2008 / 2010:
Right-click on "References" and select "Add Reference".
Select the ".NET" tab.
Look for Microsoft.Office.Interop.Excel.
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;
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)
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'.
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.
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.
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.
Related
I wanted to make a windowsforms project in my visual studio 2015 which I just downloaded. Now I want to read and write in an Excel file, so I was thinking about to use interop for it. Now I got Excel 2016 downloaded on my desktop and i got the .NET framework 3.5 and 4.6 installed. But when I try to add a reference and search in "COM" or "Assemblies" I cant find the Microsoft.Office.Interop.Excel anywhere...
How to do this?
Thanks in advance,
wouter
I had to download the Office developer tools..
Link to those: https://www.visualstudio.com/vs/office-tools/
I am developing an application which will send emails using C#. The app will be able to use templates for mail, among other things. The problem is I'm having trouble finding any Office.Interop references, which means I cannot work with Outlook.
Office is installed on my computer, but I've also tried to install the PIA from this link http://www.microsoft.com/en-us/download/details.aspx?id=3508. Unfortunately, this didn't change anything: When I launch the MSI it stops without a word, and I don't know if that is part of the problem.
Look for them under COM when trying to add the references. You should find the reference below, and possibly Microsoft Outlook 15.0 Object Library, if you need that. There are similar libraries for Word, Excel, etc.:
Update: The Object Library should contain the Interop stuff. Try to add this to a source file and see if it can now find what you need:
using Microsoft.Office.Interop.Outlook;
I forgot to select Microsoft Office Developer Tools for installation initially. In my case Visual Studio Professional 2013 and also 2015.
If you're using Visual Studio 2015 and you're encountering this problem, you can install MS Office Developer Tools for VS2015 here.
With Visual Studio 2015 I have activated it with the following steps.
Programs and Features --> Select Visual Studio > Change
Choose Modify
Windows and Webdevelopment --> Tick/select "Microsoft Office Developer Tools"
Start Update
It should work now.
You can find it at link:
C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll
Browse it then add references
If you have installed latest Visual studio and want to
To locate library of Microsoft.Office.Interop.Outlook or any other Microsoft.Office.Interop library then you should look into below 2 folders:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office14
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15
Please note that folder could be C:\Program Files\
I think you need to run that .msi to install the dlls. After I ran that .msi I can go to (VS 2012) Add References > Assemblies > Extensions and all of the Microsoft.Office.Interop dlls are there.
On my computer the dlls are found in "c:\Program Files(x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA" so you could check in a similar/equivalent directory on yours just to make sure they're not there?
You need to install Visual Studio Tools for Office Runtime Redistributable:
http://msdn.microsoft.com/en-us/library/ms178739.aspx
I had the same issue with Visual Studio Community 2013, I fixed it downloading and installing the latest update of Office Developer Tools for Visual Studio 2013. Now I am able to see the whole Microsoft.Office.Interop.* list when I go to
Add References > Assemblies > Extensions
you can download it from here:
https://www.visualstudio.com/en-us/news/vs2013-update4-rtm-vs.aspx#Office
http://aka.ms/OfficeDevToolsForVS2013
Just doing like #Kjartan.
Steps are as follows:
Right click your C# project name in Visual Studio's "Solution Explorer";
Then, select "add -> Reference -> COM -> Type Libraries " in order;
Find the "Microsoft Office 16.0 Object Library", and add it to reference (Note: the version number may vary with the OFFICE you have installed);
After doing this, you will see "Microsoft.Office.Interop.Word" under the "Reference" item in your project.
I was tying to add a Reference to Microsoft.Office.Interop.Outlook Namespace in to my web project i'm using .Net 2.0 And visual studio 2012
Question
Which one of the following is the one i should choose to work with Outlook 2010
I tried to google this and i couldn't find any thing
Or here is GAC path
C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll
you can browse manually to folder
C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\
and consequently choose Microsoft.Office.Interop.Outlook.dll
You've chosen wrong tab in Reference Manager. Choose this tab:
Then find Microsoft.Office.Interop.Outlook library. If you have multiple choice, then look at File Version info - there's a version of Office you can work with: 12.* - 2007, 14.* - 2010, 15.* - 2012.
The best choice is 14.* but the others will mostly work too.
I also need to worry you that Microsoft suggests not to use interop on server side (link)
I've created a game for an assignment in Visual Studio 2012 and the university I'm at uses 2010 and it won't open! It mentions something about NET Framework 4.5. How can I convert my project so it will open in 2010?
It takes three step:
Step 1
Open solution file (.sln) in a text editor and change
Microsoft Visual Studio Solution File, Format Version 12.00
to
Microsoft Visual Studio Solution File, Format Version 11.00
Step 2
Open application configuration file (App.config) in a text editor and change
sku=".NETFramework,Version=v4.5"
to
sku=".NETFramework,Version=v4.0"
Step 3
Open project file (for C# language .csproj) in a text editor and change
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
to
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
Now enjoy your project in VS 2010 !
You may only need to open the project in Visual Studio 2012, and go to the project's properties page.
On the Application tab, locate the Target Framework setting, and change it to .Net Framework 4.
After that, you should be able to open it in Visual Studio 2010.
Also see Converting VS2012 Solution to VS2010, but so far I haven't had to do any conversions on VS2012-created projects to open them ins VS2010 - but YMMV.
[EDIT]
I just tested this again (to be sure) by creating a .Net 4.5 project in VS2012, and verified that I couldn't open it in VS2010. Then I opened it in VS2012 again and changed the framework version to .Net 4.0. After that I could open it in VS2010.
Note that I didn't have to make any other changes. However, this is on a computer with VS2010 and VS2012 installed, so it's possible that installing VS2012 might do something with VS2010 to make it work...
I have done this at work
Open .sln file with notepad
Change the two lines below
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
To
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
and hey presto the solution now opens in VS2010
You can create a new project in Visual Studio 2010 and then right click in the solution explorer > Add > Existing item. To pull through all of files in your 2012 project.
Either create a new solution in VS2010 and add all existing files from your VS2012 or compare the .sln file to a .sln file freshly created with VS2010. At the top you'll see some version information that should be changed. Also compare the .csproj files and change any version information accordingly and the target framework.
Missing library or framework could also cause this problem. For example, if you want to open a MVC4 or Silver Light project but you don't have these libraries installed at your PC.
Open .sln file and Change Format Version to 12.0 to 11.0
I have developed an excel addin using VSTO in C#.net .Now i want to deploy this addin in other machines too .So that users who installed this can see my addin in excel menu -> Addins-> MyAddin
Alternatively can i give them just Excel with myaddin.So that whoever has this Excel can access addin and use it.This way they don't see myaddin in every excel file addins menu.
You can use a Visual Studio 2010 setup project to create a Windows Installer package. See this MSDN Link
Quote from that Link
Summary: Learn how to deploy a Microsoft Visual Studio Tools for the
Office system 2010 add-in or document- level solution using a Visual
Studio 2010 setup project to create a Windows Installer package that
targets the 2007 Microsoft Office system or Microsoft Office 2010.
Wouter van Vugt, Code Counsel
Ted Pattison, Ted Pattison Group
This article was updated by Microsoft with permission from the
original authors.
Applies to: Visual Studio 2010 Tools for Office, 2007 Microsoft Office
system, Microsoft Office 2010, Visual Studio 2010.
Download: http://code.msdn.microsoft.com/VSTO2010MSI
Contents
Overview
Deployment Methods
Deploying Office solutions that target the Visual Studio 2010 Tools for Office runtime
Download Samples Provided with this Article
Creating a Basic Installer
Conclusion
Additional Resources
About the Authors
EDIT
You may also see this link for All Users.
Conceptually, all you need to concentrate on is get yourself a COM object created which must be running even when the application (MS Excel here) is not open in the explorer.
More can be figured out from the following link :
http://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C
(P.S : link is for c# not c).
Next you should give your users a .exe file including code to create the COM object.