Years after the release of the .NET Framework, many developers are sticking with VB 6 applications developed in VBA. Many of these apps tend to work with only an occasional hiccup, while some are so involved that a quick and easy migration to .NET is nearly impossible.
The combined power of Visual Studio 2005 Tools for Office (VSTO) and Office 2007 may be enough to convince many developers to move to .NET.
With VSTO, Word and Excel are incorporated directly into the Visual Studio IDE, developers have access to .NET's vast class libraries, and there is support for IntelliSense and debugging. In Vista, meanwhile, menus, toolbars and task panes have been replaced with a customizable UI element called the ribbon, which displays the most frequently used commands.
A large concern here is getting those old VBA solutions into VSTO. How difficult will it be? What will happen to the solution once it becomes a VSTO add-in? What will and will not work?
Jan Fransen of MCW Technologies addresses these issues in the recent MSDN article, Migrating a VBA Solution to a Visual Studio Tools for Office Add-In.
The author begins by noting that not all VBA solutions should be migrated to VSTO. "If a solution has been running well for years and you do not plan to add anything new to it, it is probably best to leave it where it is," Fransen writes. On the other hand, "If you design something new, or plan major enhancements to an existing solution, or if you would like to change a document-level solution into an application-level solution, you should look carefully at what [VSTO] offers."
From there, Fransen describes his sample VBA solution and then goes through the steps necessary to migrate it to VSTO Second Edition (the version that works with Windows Vista). Topics covered along the way include Windows Forms controls, working with Web services and displaying a custom task pane.
Fransen provides both VB and C# sample code throughout the article. He also notes that familiar VBA constructs and functions will still work in VSTO.
"[I]f you are new to the .NET Framework, you might find it easier to use the VBA-style functions (such as MsgBox) and constructs (such as With…End With) that are still available to Visual Basic programmers," Fransen writes. "If you write in Visual Basic but are interested in using the .NET Framework whenever possible, take a look at the equivalent C# code for each example."