I have a Excel addin written in VBA which iterates through used range of a sheet and manipulates cell values. Its a simple addin but now user requirements have changed and I want to develop it in C# in Visual studio. For this purpose i was looking into VSTO but as far as i can understand in visual studio you can develop addin for a single version of excel. I have to give support for excel 2010 and excel 2013. What should I do to overcome this issue. which visual studio version i should use?
Any version of Visual Studio from 2010 to the present should be able to create VSTO Add-ins for Excel 2010. From VS 2012 onwards, also for Office 2013. Which set of templates you see in the later versions depends on 1) the version of Office installed and 2) the version of the .NET Framework selected when creating the project (4.0 for 2010; 4.5 for later). More information can be found on this page: https://blogs.msdn.microsoft.com/vsto/2013/03/06/office-developer-tools-for-visual-studio-2012-now-available-with-office-2013-and-net-framework-4-5-support/
Note that you should have only one version of Office installed in the development environment.
If possible, you should develop the Add-in for Excel 2010. An Add-in developed for an older version will run for a newer version, without you needing to do anything in addition - assuming Microsoft hasn't made changes to the parts of the object model you use which will "break" it. Since Microsoft pays special attention to backwards compatibility, this is usually not a problem, but thorough testing is important. It is not necessary to re-build or otherwise change the installation for installing to a newer version of Office.
One important reason to develop against the older version is that forwards compatibility is not supported. In other words, if you should use something in the newer version that's not present in the older one, that code will fail.
Also, the VSTO functionality will automatically "re-map" references made to an older set of PIAs to the newer ones for a newer version of Office. The reverse is not the case.
If for some reason it's not possible to program using the older version, as long as you have the .NET Framework 4.0 (or later) you can use the "Embed Interop types" property of a Reference to embed the PIA information in your project, so that it travels with your solution instead of referencing the PIAs installed in the GAC and makes them version independent. This is fine, in theory, but requires very thorough and careful testing since - besides the forwards compatibility problem - the actual information embedded does not always behave correctly.
you need to install visual studio 2013 for VSTO version 13 that support Excel 2013, but you can support excel 2010 by creating the installer file from the application. and there is no other way to support two different version from the code base at the same time
Thanks
Related
I'm coding one of my first projects in Visual Studio 2017 using the Microsoft Office Interop Tools to basically open some Word files, extract some content and export it to an XML file.
I know that on the target machine Office should be installed and actually on that PC a 2010 installation is licensed, while on my PC I have a 365 suite.
The first build was working only on my PC, with missing references errors to the interop library on the production PC, so I've downloaded the Microsoft Office 2010: Primary Interop Assemblies Redistributable
https://www.microsoft.com/en-us/download/details.aspx?id=3508 to include as a reference in my project, replacing the 2016 one.
First difficulty was: Once installed I cannot find the files on my drive, nor a reference inside visual studio, nor in the documentation. Is there any info about where to pick the dll?
So I unzipped from the cab the WORDPIA.DLL on an handy directory and referenced it in my project.
While is it working locally, it isn't yet on the production PC.
I'm sure I'm missing a lot of points on this topic, VS & C# are not my territory, but I need some tips to finish the project.
Go back to the original project (or reference the version of the PIAs installed on your machine). The redistributable is intended for installing to an Office 2010 machine where the PIAs were not installed. It's not meant to be used in the manner you envision.
Now click each "interop" reference entry and look at the Properties window. There should be a setting for "Embed Interop Types". Set that to True. This should make the project version-independent as it will contain the PIA information your project uses.
Note that "embed interop types" was introduced with .NET Framework 4.0 and is not available for earlier versions of the Framework. If an earlier version is a requirement, then you have to use late-binding or develop your project using Office 2010.
I wrote a .NET add-in that reference office interop assemblies with version 12 (office 2007). When I load the add-in on machines with interops with version 14, office loads this version successfully (it redirects to office 14).
BUT (and here comes the problem), on some machines it still requires version 12 although version 14 exists. Placing version 12 fixes the problem on these machines, but why does it happen???
Make sure that you don't use methds and properties introduced in later Office versions (2010 and later). Thus, you will be sure that your add-in will not fire exceptions at runtime.
The Running Solutions in Different Versions of Microsoft Office page states the following:
Solutions that were created by using Visual Studio 2013, Visual Studio 2012 or Visual Studio 2010 can run in Office 2013, Office 2010, or the 2007 Microsoft Office system. However, the solution can use only those features and APIs that are available in all three versions of Office.
BUT (and here comes the problem), on some machines it still requires version 12 although version 14 exists. Placing version 12 fixes the problem on these machines, but why does it happen???
The add-in shouldn't depend on the PIAs installed. You just need to include the required PIAs into the installer and use APIs available in the lowest Office version. That's all.
I have an addin that is compatible with Outlook 2003 - 2013 by using the various versions of VSTO.
It seems that the majority of small businesses will have the Click To Release version, which is not compatible with addins.
Is there a way to make an addin compatible with 2013 C2R, or does it need to be rewritten to be an "App" using Napa?
C2R Office installation load COM addins in exactly the same way as the regular version of the Office, there is nothing you need to do.
What is the exact problem that you are running into?
Since lately the Visual Studio Tools For Office 2012 (VSTO 2012) are available for download.
Can this new version still used for developing Add-In solutions for older Office versions (2007,2010)? Are there any advantages over VSTO 4.0 (besides Office 2013 support)
Yes, it can. I'm using VS2012 for an Excel 2007 project and it works fine.
The trick is to change the debug path in your project file so that VS uses the older version of the Office app your plugin is for.
Create your VSTO project (let VS create the project for Office 2010)
Edit the project file and find the <ProjectProperties> with a HostName attribute. It will be a child element of a <VisualStudio> element.
Change the DebuginfoExeName attribute value of the <ProjectProperties> attribute to be the path to the older version of the Office application .exe file
Save your project
Now when you go to debug your app it should launch the older version of your Office app and attach to that process to load your VSTO.
In my project, the new <ProjectProperties> element looks like this for Excel 2007:
<ProjectProperties
HostName="Excel"
HostPackage="{20A848B8-E01F-4801-962E-25DB0FF57389}" OfficeVersion="14.0"
VstxVersion="4.0"
ApplicationType="Excel"
Language="cs"
TemplatesPath=""
DebugInfoExeName="#Software\Microsoft\Office\12.0\Excel\InstallRoot\Path#excel.exe"
AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
Deployment also works fine. I deploy my add-in via ClickOnce and it is added to Excel 2007 clients without any additional changes.
As far i know you can deploy your solution to previous version office. I once developed an add-in for ppt 2013 and it worked fine in ppt 2010. Note that The API for the new VSTO has several additional features and last time i only used existing features, but not the new ones.
I've never tested this, but i think if you use new event handler that only works in 2013, when you deploy it in 2010 it simply does nothing / doesn't work.
As i mentioned, the obvious advantage of new VSTO is more features available, for example in ppt 2013, it has event handler when the users do dragging, you should checked them by yourselves. If your solution doesn't need these new features, you can develop it in the previous version of VSTO to make sure the backward compatibility.
I just created a VSTO Add-In for Office 2010. How how do I know which pre-requisites I need and whether or not my add-in would work for both 2010 and 2007 or just 2010? I'm confused why this seems obvious based on the lack of documentation on this topic. During compilation it tells you if there is a problem if you're building for instance on .NET Client profile instead of the full .NET but for all the other prerequisites I don't know how to tell. Do I need for instance the Visual Studio for Office 2010 Runtime and the Interlop Assemblies?
This might be of interest:
https://stackoverflow.com/a/4411365/1373170
and https://stackoverflow.com/a/1596868/1373170
If you are on .NET 4, you don't need to ship PIA anymore, if you use embedded interop assemblies.
The VSTO Runtime would still be required I believe.