Freigeben über


VBA and Office solutions in Visual Studio compared

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Microsoft Visual Basic for Applications (VBA) uses unmanaged code that is tightly integrated with Office applications. Microsoft Office projects created by using Visual Studio enable you to take advantage of the .NET Framework and Visual Studio design tools.

For information about the types of Office solutions you can create by using Visual Studio, see Office solutions development overview (VSTO).

Comparison

The following table provides a basic comparison between VBA solutions and Office solutions in Visual Studio.

VBA solutions Office solutions in Visual Studio
Uses code that is connected to and persisted with a specific document. Uses code that is stored separately from the document (for document-level customizations), or in an assembly that is loaded by the application (for VSTO Add-ins).
Works with the Office object models and VBA APIs. Provides access to both the Office object models and the .NET Framework APIs.
Designed for macro recording and a simplified developer experience. Designed for security, easier code maintenance, and the ability to use the full Visual Studio integrated development environment (IDE).
Works well for solutions that benefit from a tight integration with Office applications. Works well for solutions that benefit from the full resources of Visual Studio and the .NET Framework.
Has limitations for the enterprise, especially in the areas of security and deployment. Designed for use in the enterprise.

Some things are still easier to do quickly using VBA. Specifically, you might want to continue using VBA for:

  • Custom worksheet functions.

  • Macro recording.

Combine VBA solutions and Office solutions created by using Visual Studio

You can call VBA code from Office solutions created by using Visual Studio, and you can also call code in Office solutions created by using Visual Studio from VBA. The specific technique differs depending on whether your Office solution is a VSTO Add-in or a document-level customization. For more information, see Call code in VSTO Add-ins from other Office solutions and Combine VBA and document-level customizations.

See also