Declarations

You must declare every Windows API function that you use, period. Unlike in VBA, the Windows API includes no type library against which to resolve your function calls. So for them to be resolved—and you must resolve all function calls—you have to declare each one before you use it. The following code shows how to declare a function call:

Public Declare Function SetForegroundWindow Lib "user32.dll" _ (ByVal hwnd As Long) As Long

The syntax breakdown is as follows:

[Scope] Declare Function <FunctionName> (List of Parameters) As <DataType>

The easiest way to get the declaration is to use the API Viewer (which is available at msdn.microsoft.com) shown in Figure 18-1.

Lib <DLL Filename string>

Vba Excel Missing Library Autocad
Figure 18-1. The API Viewer dialog box

Was this article helpful?

0 0

Post a comment