Jun 23 2009

Upgrading VSTO VS2005 Excel 2003 Application to a VSTO VS2008 Excel 2007

Just documenting my experience of upgrading my development environment and an Excel 2003 application I wrote.

Out of the gate:

Opening up the solution using VS2008 (and having Office 2007 installed), there was an automatic conversion of the .xls to a .xlsx file and the new project automatically targetted the .net 3.5 framework. All seemed good, except...

1.) I had some code in my project that I copied from somewhere that apparently doesn't work any longer with the new VSTO. I do not have a solution yet to get paste this yet, but I will be looking at that closer in the coming days. Here is some of the code. The new VSTO API apparently doesn't have the RuntimeCallback object in it any longer. I am using this because I am creating Excel Worksheets dynamically in code and I am putting controls on them like dropdowns and radio buttons. I am having to keep a reference to the worksheet in a hash table so that I can always get back to it when a radio button is clicked, etc. I don't pretend to totally understand this, and it has been a while since I coded this, but I do remember having to do this "hack" to be able to get access to the worksheet controls again once the user moved to another worksheet. The object "CurrentWorksheet" no longer saw the dynamic controls on the page so I could do nothing with them. Here is a post that talks about this issue, but didn't help me resolve this issue.

UPDATE: Here is THE solution to this issue in VSTO 2007/8 (whatever it is being called). It can basically be found in the post referenced below on New GetVstoObject method? First your workbook and worksheet code pages need to import Microsoft.Office.Tools.Excel.Extensions. Then in the Workbook_Startup event you need to force VBA to startup on the Excel worksheet with a line of code like this: Dim temp As Object = Me.VBProject. After that, then you can take a reference to an Interop worksheet and can call the new GetVstoObject method and BAM - you have your full featured worksheet host item with full access to all of your controls and such.

Dim hostItemProvider As Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider = CType(RuntimeCallback.GetService(GetType(Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)), Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)

2.) Next I wanted to target the .net 2.0 framework with this project because my users don't have the 3.5 framework on their PCs. Changing this the target framework cause me to have this compile-time build failure with this error message: "EntryPoint not specified for manifest targeting Framework version". Well, a little binging lead me to this forum discussion. The bottom line of what was posted: ".NET 3.5 is a requirement to use the new ClickOnce publishing and deployment options in VS2008. the ClickOnce publishing and deployment feature is only applicable to the 2007 Microsoft Office system. If you do choose to use ClickOnce, manifests must be signed with a certificate. For more information about ClickOnce deployment, see http://msdn2.microsoft.com/en-us/library/bb386179(VS.90).aspx. If you choose to use .NET 2.0 with VS2008, you can only develop for Office 2003." Ok - so I guess my plan has to be to upgrade my users to the .net framework 3.5.

This upgrade is done and working! Woot! Now just need to deploy again and start having users test it. I anticipate that the users will need to have .NET 3.5 sp1 installed before this will work for them. I am also guessing they will need the new VSTO runtime. I guess we will see... more on that later!

Other Helpful Links:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Jun 23 2009

Export to Excel 2007 throwing a Corrupted file warning?

Check this blog post from the "VS Office Developer Escalation team at Microsoft Support".

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5