InfoQ

News

Working with VBA and Visual Studio Tools for Office

Posted by Jonathan Allen on Nov 09, 2009

Community
.NET
Topics
Office Business Applications ,
Interop
Tags
Visual Basic for Applications ,
Visual Studio Tools for Applications ,
Microsoft Office ,
Visual Studio Tools for Office

Visual Basic for Applications is a dead-end. Though still shipped with Office and still wildly popular with power-users, development on it has long since ceased. Someday Visual Studio Tools for Applications (VSTA) is supposed to replace VBA, but it currently isn’t getting a lot of attention. Even its portal on MSDN has been pulled down, leaving only the occasionally blog post.

This leaves Visual Studio Tools for Office (VSTO) for those who want to leverage the power of .NET from within Office-based products. Rather than being embedded within a document, VSTO projects are external to Office. This allows them to be compiled into standard DLLs, deployed via OneClick or standard MSI packages, and be easily shared amongst several documents.

Most power users are not likely to want to learn compiled VB.NET or C# development. Likewise, developers are probably not going to want to rewrite all of their companies VBA resources, especially the parts currently being maintained by said power users. This means interoperability between VSTO and VBA is going to be vital for several years to come.

As Beth Massi explains, there are two ways to integrate VBA and VSTO. The easiest is to simply call the VBA macro from within VSTO by using the Application.Run method. Since the macro is specified by name, you won’t know until runtime if the macro is missing or simply mistyped.

The second method Beth Massi describes is calling VSTO code from within VBA macros. Before you can do this, the EnableVbaCallers property must be set, which will cause the VSTO code to be registered for COM interopt. Then you can use the GetManagedClass function to access the VSTO methods and properties you exposed.

You can see a complete walkthrough of both scenarios using Excel on Beth Massi’s blog.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.