Declare Statement

Named Arguments

No

Syntax

Syntax for subroutines

[Public | Private] Declare Sub name Lib "libname" _
      [Alias "aliasname"] [([arglist])]

Syntax for functions

[Public | Private] Declare Function name Lib "libname" 
      [Alias "aliasname"] [([arglist])] [As type]

Public

Use: Optional

Keyword used to declare a procedure that has scope in all procedures in all modules in the application.

Private

Use: Optional

Keyword used to declare a procedure that has scope only within the module in which it's declared.

Sub

Use: Optional

Keyword indicating that the procedure doesn't return a value. Mutually exclusive with Function.

Function

Use: Optional

Indicates that the procedure returns a value. Mutually exclusive with Sub.

name

Use: Required

Data Type: String

Any valid procedure name within the DLL or code library. If the aliasname argument is used, name represents the name the function or procedure is called in your code, while aliasname represents the name of the routine as found in the external library.

Lib

Use: Required

Keyword indicating that the procedure is contained within a DLL or other code library.

libname

Use: Required

Data Type: String

The name of the DLL or other code library that contains the declared procedure.

Alias

Use: Optional

Keyword whose presence indicates that name is different from the procedure's real name within the DLL or other code library.

aliasname

Use: Optional

Data Type: String

The real name of the procedure within the DLL or code library.

arglist ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.