Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm working on a VSTO add-in for Word 2010 (.NET Framework 4.6.1) in C#. This add-in is meant to produce Word documents from a template, using data from a few sources, a few of which (depending on the ) being one or more Excel workbooks.

I have been perusing the MSDN literature, but I feel as if I'm missing a crucial step.

Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects ? They each seem to rely on the Factory.GetVstoObject() method, which uses a factory object that is application-specific. I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.

I have been playing around with having two add-ins, one targeting Word and one targeting Excel, but I'm having a hard time getting them to see each other. If this isn't achievable as a VSTO add-in, can you reference multiple Office application object models in a standalone executable?

Could you provide more specific information about what you want to do? It's not possible to give you an accurate answer without more detailed information. There are lots of ways to "interop" with Office applications... Cindy Meister Apr 6, 2018 at 5:11

Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects

Maybe not those exact types but you can find something similar. You can always drop down to pure COM/Ole Automation level completely by-passing VSTO APIs. Office is still exposing a COM API which VSTO I suspect is just wrapping into nicer c# classes.

e.g. from a c# Excel VSTO add-in you can fire up word document by:

var type = Type.GetTypeFromProgID("Word.Application"); dynamic app = Activator.CreateInstance(type); app.Visible = true; dynamic doc = app.Documents.Add(); doc.Content.InsertAfter("Hello world!"); catch (Exception ex) MessageBox.Show(ex.ToString());

Note: I am using dynamic (one of the main purposes of dynamic in c# was to make COM easier) here so as to avoid dependence on any specific COM-type library. It's version neutral so it should work any Word version.

I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.

In what sense?

See also

  • Where to find OLE Automation's documentation , specifically this answer
  • I was having trouble accessing fields in the Word and Excel interop objects, but after reviewing the documentation I have figures out what I needed to do (which I previously thought was not possible). Thank you! PTLEng Apr 6, 2018 at 18:48

    Disclaimer I never have done any shared add-in I'm going to talk about here (@ Cindy Meister would know more)

    Till VS 2010 you could create a project called Office Shared add-in. Here is how it looked like in VS 2003 This would be, probably, something what you would need but as said it's no longer available and I seem to remember there were some issues with it anyway.

    I found this post where the guy is trying to use something what would mimic the Office Shared add-in template. He claims it's working so that would be worth to try.

    Otherwise you would have to use the Office PIA as @ MickyD answered

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .