16

I got the sources of a .NET project that I am trying to compile. Although, the project uses the reference (namespace) Microsoft.Office.Interop.Word from Office 2010 that I cannot find anywhere. I was able to download the file microsoft.office.interop.word.dll but apparently the one from Office 2007 since it still doesn't compile because the project uses the function Document.SaveAs2 (which is from Office 2010 library). I have Office 2007 on my computer and Visual Studio 2012 Express for Desktop.

Could you please explain me how this works? How come was I able to download the dll but I cannot find the one from Office 2010. How come my client was able to compile the projet without this dll? Does Visual Studio automatically "connects" to the Microsoft Office libraries if installed when compiling ?

Thank you for your help.

wattostudios
  • 8,666
  • 13
  • 43
  • 57
mentinet
  • 744
  • 3
  • 9
  • 23
  • you should install office 2010. – Hamid Pourjam Mar 09 '15 at 14:28
  • are you familiar with hot to add references..? right click on the reference node.. click `add Reference` got to `COM` node on the left and look for Microsoft.Office , or try adding the using Microsoft.Interop.Office name space – MethodMan Mar 09 '15 at 14:28
  • I eventually installed Office 2010 but still cannot resolve my issue. That is because I have `using Microsoft.Office.Interop.Word;` but didn't add the reference that I get an compilation error. I tried adding the reference as you suggest MethodMan, but I cannot find any Microsoft.Office... Thank you for your help. – mentinet Mar 09 '15 at 14:54
  • Take a look at this [nuget](https://www.nuget.org/packages/Microsoft.Office.Interop.Word/) package – VivekDev Aug 28 '16 at 11:42

5 Answers5

16

You shouldn't be searching for the dll on your local system yourself if you installed the assemblies correctly. See following link for information on how to download and install office interop libraries without installing office. Second link details how to add the assemblies to your project correctly.

Install Office Primary Interop Assemblies

Office Primary Interop Assemblies

For a further reference here are some pictures detailing how to add the dll correctly:

In your project, right-click on "References" and select "Add" and then "Reference".

Add References

Next select "Extensions" in the Reference Manager, scroll to find the correct dll. Which for Microsoft.Office.Interop.Word.dll Office 2010 is the version 14 one.

Add dll

Bilal Bashir
  • 1,443
  • 14
  • 18
  • Thank you for your clear answer Slowbrochacho. So I have got Office 2010 installed, I downloaded, extracted and installed the Primary Interop Assemblies but I still cannot find the Microsoft.Office.Interop.Word in the references under Assemblies/Extensions. How would you explain this? Thank you – mentinet Mar 09 '15 at 15:03
  • 1
    Run the following command in your VS studio command line, "gacutil /l Microsoft.Office.Interop.Word" to see if the dll is loading in your global assembly cache. – Bilal Bashir Mar 09 '15 at 15:09
  • It seems good. I guess I have got the version for Office 2007 (still installed and the one for 2010) ? See here : http://img11.hostingpics.net/pics/44086520150309161607FindingtheVisualStudioCommandPromptsinVisualStudio2012VisualCTea.png – mentinet Mar 09 '15 at 15:17
  • 1
    Check in the reference manager in your project under COM -> Type Libraries for "Microsoft Word 15.0 Object Library" as well to make sure that the COM references are correct. – Bilal Bashir Mar 09 '15 at 15:25
  • I have not Microsoft Word 15.0 Object Library but the 14.0. Although I have Microsoft Office 15.0 Object Library. Thank you – mentinet Mar 09 '15 at 15:48
  • It seems to work if I add Microsoft word 14.0. It adds a reference Microsoft.Office.Interop.Word. Is this the same as adding the reference from Assembly > Extensions then Microsoft.Office.Interop.Word? – mentinet Mar 09 '15 at 15:55
  • 1
    Try selecting that and try to rebuild it should use the last loaded interop assembly (should be version 14 since you just installed office) from your GAC, this is only good for building in development and shouldn't be done for deployment purposes. – Bilal Bashir Mar 09 '15 at 15:57
  • 1
    How can this be an issue if I build the app like this for production deployement purpose? – mentinet Mar 09 '15 at 16:04
  • I should probably double check on this but, I am pretty sure that if you reference a dll in your systems GAC it will look for the dll on the clients system's GAC and if they don't have the assemblies installed or registered or have an incorrect version as the last loaded dll then your application won't work so, it is a good idea to provide the assemblies with your redistributable or have the install procedure download and install the dlls into the client's GAC. – Bilal Bashir Mar 09 '15 at 21:24
  • It can be also found at this location C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA – Jay Dubal Dec 22 '17 at 09:10
3

Install via nuget Microsoft.Office.Interop.Word.

Matheus Miranda
  • 1,755
  • 2
  • 21
  • 36
  • 1
    Caution! this package is great but _not_ created by Microsoft and doesn't support Office 14 (2010). Just worth noting – matt.s May 01 '20 at 17:36
2

Now that Visual Studio 2019 is out, you can install Microsoft Office interop libraries as part of an optional bundled component called Visual Studio Tools for Office (VSTO).

Microsoft have made this super easier, and you don't need to reference them in the GAC!

CrazyTim
  • 6,695
  • 6
  • 34
  • 55
  • beware that will install a lot of other stuff also. Is it relevant, I don't know –  Mar 18 '20 at 14:09
1

If you have Office 2016 installed, you can get the file Microsoft.Office.Interop.Word.dll here:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Word.dll

Ashok Jingar
  • 111
  • 1
  • 7
0

I manage to get the Microsoft.Office.Interop extensions listed in the suggested references after installing the Office Tools Bundle installer for VS2012 available here: http://blogs.msdn.com/b/somasegar/archive/2013/03/04/now-available-office-developer-tools-for-visual-studio-2012.aspx

mentinet
  • 744
  • 3
  • 9
  • 23