API Basics

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The purpose of the Microsoft® Windows® API is to make it possible for you to develop programs consistent with the Windows operating system and user interface. Instead of individuals writing the code to create components of the Windows operating system, such as forms, command buttons, and menus, you can call the appropriate functions in the Windows API and let the operating system create those components. Because the Windows API is a complex set of functions, this documentation will give you a starting point and direct you to other resources if you find you must know more. You can apply the skills you learn in calling the Windows API to calling DLL functions in other DLLs as well.

In This Section

  • What Is an API?
    API stands for application programming interface. An API is a set of functions you can use to work with a component, application, or operating system.
  • Why Use VBA to Call the Windows API?
    VBA is a powerful tool for building Windows applications. With VBA, however, you have control over only a small portion of the operating system — the part that is available through the functions and objects exposed directly to VBA in your application.
  • API Resources
    To call functions in the Windows API, or any API for that matter, you must have documentation describing the available functions, how to declare them in VBA, and how to call them.
  • Accessing Functions in a DLL
    Before you can call a function in a DLL from VBA, you must provide VBA with information about where that function is and how to call it.
  • Anatomy of a Declare Statement
    Examine an example of the Declare statement for the GetTempPath function, which returns the path to the Windows temporary folder.
  • Constants and User-Defined Types
    In addition to the Declare statement for a DLL function, some functions require you to define constants and types for use with that function.
  • Understanding Handles
    A handle is a 32-bit positive integer that Windows uses to identify a window or another object, such as a font or bitmap.
  • The Windows API and Other Dynamic-Link Libraries
    One of the most powerful features of Visual Basic for Applications (VBA) is its extensibility. You can extend your applications by calling functions in the Microsoft® Windows® application programming interface (API) and other dynamic-link libraries (DLLs).
  • Calling DLL Functions
    Although calling DLL functions is in many ways similar to calling VBA functions, there are differences that might make DLL functions confusing at first.
  • Wrapping DLL Functions
    If you call DLL functions frequently, you might want to simplify the process by encapsulating those functions within class modules.