none
VSTO vs Office Interop API Extensions RRS feed

  • Question

  • Is VSTO and Office Interop API Extensions are different technologies or set of tools for office development and customization?

    If yes then which one to use and study?

    I was reading the article from the following link and looks the author is doing same thing with the two different ways.

    http://blogs.msdn.com/philliphoff/archive/2008/02/21/parameterized-properties-and-the-office-interop-api-extensions.aspx

    Also why there are two namespaces for office excel, which one is good to use for office development:

    Microsoft.Office.Interop.Excel namespace 
    Microsoft.Office.Tools.Excel namespace

    I am VBA developer new to VSTO and trying to find out my way in right direction.

    Thanks and regards,

    VS
    Thursday, April 9, 2009 11:43 PM

Answers

  • Hi VS

    Please keep in mind that, for the most part, the forums are monitored by volunteers. There is no set time within which you can expect a reply, a business will tend to be especially during a time that is considered, in many parts of the world, to be a religious holiday :-)

    In case you haven't found it, yet, the official VSTO documentation on MSDN starts here. You'll find some additional resources listed in the forum's Please Read Next message. The entry point for general Office Development is this page.

    That's a lot of information and it can at first be confusing, indeed :-)

    The Office PIAs (Primary Interop Assemblies) are basically the "translator" between the Office COM type libraries (*.tlb, *.olb) and the .NET world. .NET is different enough from COM that the "same thing" doesn't always match up. One simple example is the data type Long Integer in VBA. In the .NET World, the same structure is called an "Integer" and a "long integer" is larger than anything the classic Visual Basic language supports. So an Interop Assembly takes care of making sure COM and .NET are communicating on the same wavelength. A Primary Interop Assembly is an Interop Assembly that's been issued by the software manufacturer (Microsoft, in this case). It's often optimized, and it serves as a common "contract" between all developers. Everyone can share and use this one set of IAs and be assured of the result.

    (This may be getting deeper than you want to go, but in clarification of the last sentence: If you set up a reference to a COM library in a .NET project, .NET will take care of creating a set of IAs for you to use with your project. It will, by default, include them in your deployment, as part of your project. But only your project will know about them and can use them. This would mean that every Office developer could end up distributing his own set of IAs, which can lead to problems. PIAs, installed in the GAC (Global Assembly Cache) by the software manufacturer are something all developers can use, so each won't be distributing his own version.)

    Every .NET developer who wants to automate Office needs to use the PIAs. (Unless he uses late-binding, same as in VBA.)

    VSTO is a sub-set of Office development. It's a specific set of Tools the developer can use to streamline and enhance interaction with the Office applications. VSTO uses the PIAs, but is not the creator or owner of them. The PIAs are necessary for VSTO to run, just as the Office application must be present for VSTO to run.

    Office can be automated without VSTO basically in the ways with which you may be familiar, for example a VB6 Forms project that interacts with an Excel workbook. Or a COM Add-in created in VB6 can also be created using VB.NET.

    The two namespaces you list:
    Microsoft.Office.Interop.Excel is the one assoicated with a reference to the PIAs. Every Office developer can/will/"must" use it.

    Microsoft.Office.Tools.Excel is a namespace belonging to the VSTO technology - it was created by the developers of the "Tools". The classes it contains extend the Office application for the developer. For example, in Word I have to type Doc.Bookmarks(index).Range.Text to write text to a bookmark and I have to recreate the bookmark around the text in order to retain it. Using the "Tools" Bookmark I can do this: thisVSTODoc.Bookmarks(index).Text, and the Tools also take care of recreating the bookmark.

    You may find the book "VSTO for Mere Mortals" helpful for getting a handle on VSTO. It was written explicitly for people migrating from VBA.

    BTW, the link you give: If you're going to stick with VB.NET then you don't need to worry about the discussion at all - it's not relevant to you (and soon won't be to C# developers, when C# 4.0 is released later this year).

    I hope this clears a couple of things up for you :-)



    Cindy Meister, VSTO/Word MVP
    Friday, April 10, 2009 3:06 PM
    Moderator

All replies

  • Any comment on the above post please.

    Thanks and regards,
    Friday, April 10, 2009 2:29 PM
  • Hi VS

    Please keep in mind that, for the most part, the forums are monitored by volunteers. There is no set time within which you can expect a reply, a business will tend to be especially during a time that is considered, in many parts of the world, to be a religious holiday :-)

    In case you haven't found it, yet, the official VSTO documentation on MSDN starts here. You'll find some additional resources listed in the forum's Please Read Next message. The entry point for general Office Development is this page.

    That's a lot of information and it can at first be confusing, indeed :-)

    The Office PIAs (Primary Interop Assemblies) are basically the "translator" between the Office COM type libraries (*.tlb, *.olb) and the .NET world. .NET is different enough from COM that the "same thing" doesn't always match up. One simple example is the data type Long Integer in VBA. In the .NET World, the same structure is called an "Integer" and a "long integer" is larger than anything the classic Visual Basic language supports. So an Interop Assembly takes care of making sure COM and .NET are communicating on the same wavelength. A Primary Interop Assembly is an Interop Assembly that's been issued by the software manufacturer (Microsoft, in this case). It's often optimized, and it serves as a common "contract" between all developers. Everyone can share and use this one set of IAs and be assured of the result.

    (This may be getting deeper than you want to go, but in clarification of the last sentence: If you set up a reference to a COM library in a .NET project, .NET will take care of creating a set of IAs for you to use with your project. It will, by default, include them in your deployment, as part of your project. But only your project will know about them and can use them. This would mean that every Office developer could end up distributing his own set of IAs, which can lead to problems. PIAs, installed in the GAC (Global Assembly Cache) by the software manufacturer are something all developers can use, so each won't be distributing his own version.)

    Every .NET developer who wants to automate Office needs to use the PIAs. (Unless he uses late-binding, same as in VBA.)

    VSTO is a sub-set of Office development. It's a specific set of Tools the developer can use to streamline and enhance interaction with the Office applications. VSTO uses the PIAs, but is not the creator or owner of them. The PIAs are necessary for VSTO to run, just as the Office application must be present for VSTO to run.

    Office can be automated without VSTO basically in the ways with which you may be familiar, for example a VB6 Forms project that interacts with an Excel workbook. Or a COM Add-in created in VB6 can also be created using VB.NET.

    The two namespaces you list:
    Microsoft.Office.Interop.Excel is the one assoicated with a reference to the PIAs. Every Office developer can/will/"must" use it.

    Microsoft.Office.Tools.Excel is a namespace belonging to the VSTO technology - it was created by the developers of the "Tools". The classes it contains extend the Office application for the developer. For example, in Word I have to type Doc.Bookmarks(index).Range.Text to write text to a bookmark and I have to recreate the bookmark around the text in order to retain it. Using the "Tools" Bookmark I can do this: thisVSTODoc.Bookmarks(index).Text, and the Tools also take care of recreating the bookmark.

    You may find the book "VSTO for Mere Mortals" helpful for getting a handle on VSTO. It was written explicitly for people migrating from VBA.

    BTW, the link you give: If you're going to stick with VB.NET then you don't need to worry about the discussion at all - it's not relevant to you (and soon won't be to C# developers, when C# 4.0 is released later this year).

    I hope this clears a couple of things up for you :-)



    Cindy Meister, VSTO/Word MVP
    Friday, April 10, 2009 3:06 PM
    Moderator
  • VS,

    Cindy is too kind and too helpful with an excellent write up about the PIA and namespaces.

    As for the book recommendation I would like to suggest:
    Visual Studio Tools for Office 2007: VSTO for Excel, Word, and Outlook (Microsoft .NET Development Series) by Eric Carter, Eric Lippert

    This book will give more detailed information about VSTO and also cover more in detail each program in the Office suite then "VSTO for Mere Mortals".  


    Kind regards, Dennis (http://xldennis.wordpress.com/)
    Friday, April 10, 2009 5:36 PM
  • Thanks Cindy for detailed explaination.

    Dennis - Thanks for recommending the book.

    I just bought this book last week and I am going through it.

    Thats why my question raised while reading the book.

    Thanks and regards for your help.
    Friday, April 10, 2009 5:43 PM