Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Declare - Alias Statement

  • Last UpdatedJul 18, 2023
  • 2 minute read

In the previous Declare statement example, the name of the declared function in VBA is the same as the name of the actual function within the DLL. This does not necessarily have to be the case. There are some instances where the name of the function in the DLL is incompatible with the naming structure of VBA, and cannot be used as a declared function name in VBA. An example would be those DLL function names that start with an underscore.

To overcome such incompatibilities, the VBA Declare statement supports the use of an alias name for the DLL function, through the use of the optional Alias statement . The Alias statement consists of the Alias keyword, followed by the actual name of the DLL function contained within string double quotes. The Alias statement must be positioned within the Declare statement between the Lib statement and the Argument statement.

Here's an example of the Declare statement for the Windows API GetTempPathA function as used above, however, this time using the optional Alias statement:

Declare Function GetWinTempPath Lib "kernel32" _
(Byval nBufferLength As Long, _ Alias "GetTempPathA" _
Byval lpBuffer As String) As Long

In this example, the name of the API function in the DLL is GetTempPathA, and the name by which you would call this function from VBA is GetWinTempPath. Note that the actual name of the DLL function appears contained within string double quotes positioned after the Alias keyword. This instructs VBA to use the alias function name when calling the DLL.

Because an alias allows you to name a declared DLL function anything you want in VBA, you can make the function name conform to your own naming standards.

Note: DLL functions are case sensitive; VBA function names are not. When declaring DLL functions in VBA, be careful to accurately remain case sensitive in the declaration.

See Also

Functions

Passing Variables Byref and Byval

Passing Arguments to DLL Functions from VBA

DLLs and APIs

TitleResults for “How to create a CRG?”Also Available in