Using the Windows API

VBA can borrow methods from other files that have nothing to do with Excel or VBA—for example, the Dynamic Link Library (DLL) files that Windows and other software use. As a result, you can do things with VBA that would otherwise be outside the language's scope.

The Windows Application Programming Interface (API) is a set of functions available to Windows programmers. When you call a Windows function from VBA, you're accessing the Windows API. Many of the Windows resources used by Windows programmers are available in DLLs, which store programs and functions and are linked at runtime rather than at compile time.

Excel itself uses several DLLs, for example. The code in many of these DLLs could have been compiled right into the excel.exe executable file, but the designers chose to store it in DLLs, which are loaded only when needed. This technique makes Excel's main executable file smaller. In addition, it is a more efficient use of memory because the library is loaded only when it's needed.

DLLs are also used to share code. For example, most Windows programs use dialog boxes to open and save files. Windows comes with a DLL that has the code to generate several standard dialog boxes. Programmers thus can call this DLL rather than write their own routines.

If you're a C programmer, you can produce your own DLLs and use them from VBA. Microsoft's Visual Basic language also has the capability to create DLL files that can be called from Excel.

Was this article helpful?

0 0

Post a comment