Nobody beats the sheer productivity of developers targeting the Microsoft Office System. Whether you're building applications for Word or Excel, well-established platforms like Visual Basic for Applications let you hit the ground runningand solve many real-world business problems quickly.
But while thousands (many thousands) of developers like you have been leveraging VBA with good results, there's always been a disconnect between what you could do on the desktop versus what other programmers were able to create using Visual Studio.
VBA allows you to create a lot of automation, dynamic formatting, reports and links to external data sources, but even the most talented Office solutions provider finds it less of a breeze to truly integrate Word and Excel with client/server systems, Exchange servers, and the Internet. By the same token, Visual Studio coders were disadvantaged because they couldn't leverage the rich applications infrastructure and familiar interfaces behind Office.
That's changingbig timethanks to .NET Framework, the managed-runtime environment that Microsoft introduced a couple of years ago, and which serves as the foundation for Microsoft's current and future desktop and server applications.
Initially, .NET applications for the desktop (written in Visual Basic .NET and Visual C#) were similar to traditional native code apps (written in Visual Basic and C++)they were intended to be standalone programs. But more recently, Microsoft has extended the .NET programming model into Office, using a system called Visual Studio Tools for the Microsoft Office System (version 2003 or the up-coming version 2005) or VSTO. Microsoft is upgrading the initial 2003 release of VSTO; the new 2005 version makes it even easier to build connected desktop applications around Office.
The upshot: Using VTSO 2005, you can take advantage of Visual Studio 2003 and powerful languages like VB.NET and C# to do virtually everything you could do with VBAand much, much more.
Let's take a look at how the .NET Framework fits in with Office, and how to get started writing Office applications using Visual Studio and VSTO.
Introducing the .NET Framework, Visual Studio, and VSTO
In case you've not been working with .NET, here's the quick overview.
The .NET Framework is a runtime environment that runs on Windows XP desktops, Windows 2000 servers and desktops, and Windows Server 2003. It's more than a simple language interpreter, like VB6Run.exe: .NET provides an incredibly rich set of libraries and functions for managing the user interface, communicating across the network, publishing and consuming XML Web Services, accessing the file system and relational databases, and more.
(There's a subset of the managed runtime that runs on handhelds, called the .NET Compact Framework, but it doesn't play a role in Office automation.)
One advantage of .NET is that it provides a lot more security than the base Windows operating system: The managed environment is often referred to as a "sandbox" where applications can only do what they're authorized and authenticated to do. The .NET Framework is also fast, efficient, and multi-language, meaning that you can write applications in a number of languages, including Visual Basic, and C#, which is a new language that combines the productivity of Visual Basic with the fine-grained control offered by C++.
The concept of a managed runtime should be familiar to Office developers, though the term itself is new. Your VBA applications, running within Word or Excel, are actually running within a limited managed runtime environment inside the Office system. One difference with .NET and VSTO is that .NET applications execute within the .NET-managed runtime, instead of within the Office applications themselves.
To enable that code separation, Microsoft created extensive hooks in Office 2003 that allow .NET applications built using VTSO to provide the rich automation and communications capabilities that you've always experienced with VBAbut to also take advantage of every available feature of the .NET Framework environment.
To continue our definitions:
Visual Studio is the Multilanguage development environment that Microsoft offers for both .NET and "native" binary applications for Windows. (When building Office automation solutions, however, we're only concerned with developing .NET apps.). While Visual Studio may appear somewhat overwhelming to someone who's not used to .NET, it's a very efficient and comfortable environment once you've made the transition. For a good introductory, see "Don't Freak Out About Visual Studio."
Visual Studio Tools for the Microsoft Office System, or VSTO, is a set of libraries that plugs into Visual Studio to provide all the functionality needed to control Office applications using languages like Visual Basic and C#. Among other things, VSTO lets you program to Office's XML schemas. The initial release, VSTO 2003, lets you program Word and Excel using Visual Studio. VSTO 2005, now in beta, improves those capabilities, tightens the integration between Office and .NET, and lets you develop custom applications using InfoPath. VSTO is available as part of an MSDN Universal subscription, or you can buy it as a separate add-on to Visual Studio.