Stats

100 Contributors: 1 Monday, June 26, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

API Calls

Introduction

API stands for Application Programming Interface

API's for VBA imply a set of methods that allow direct interaction with the operating system

System calls can be made by executing procedures defined in DLL files

Remarks

Common operating environment library files (DLL's):

Dynamic Link LibraryDescription
Advapi32.dllAdvanced services library for APIs including many security and Registry calls
Comdlg32.dllCommon dialog API library
Gdi32.dllGraphics Device Interface API library
Kernel32.dllCore Windows 32-bit base API support
Lz32.dll32-bit compression routines
Mpr.dllMultiple Provider Router library
Netapi32.dll32-bit Network API library
Shell32.dll32-bit Shell API library
User32.dllLibrary for user interface routines
Version.dllVersion library
Winmm.dllWindows multimedia library
Winspool.drvPrint spooler interface that contains the print spooler API calls

New arguments used for the 64 system:

TypeItemDescription
QualifierPtrSafeIndicates that the Declare statement is compatible with 64-bits. This attribute is mandatory on 64-bit systems
Data TypeLongPtrA variable data type which is a 4-bytes data type on 32-bit versions and an 8-byte data type on 64-bit versions of Office 2010. This is the recommended way of declaring a pointer or a handle for new code but also for legacy code if it has to run in the 64-bit version of Office 2010. It is only supported in the VBA 7 runtime on 32-bit and 64-bit. Note that you can assign numeric values to it but not numeric types
Data TypeLongLongThis is an 8-byte data type which is available only in 64-bit versions of Office 2010. You can assign numeric values but not numeric types (to avoid truncation)
ConversionOperatorCLngPtr Converts a simple expression to a LongPtr data type
ConversionOperatorCLngLng Converts a simple expression to a LongLong data type
FunctionVarPtrVariant converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit (4 bytes)
FunctionObjPtrObject converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit (4 bytes)
FunctionStrPtrString converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit (4 bytes)

Full reference of call signatures:

Related Examples