Using the Any Data Type

Some DLL functions have an argument that can take more than one type of data. In the Declare statement for a DLL function, such an argument is declared as type Any. VBA makes it possible for you to pass any data type to this argument. However, the DLL function might be designed to accept only two or three different types of data, so passing in the wrong type of data might cause an application error.

Usually, when you compile your code in a VBA project, VBA performs type-checking on the values you pass for each argument. That is, it ensures the data type of the value passed in matches the data type for the argument in the function definition. If you define an argument as type Long, for example, and you attempt to pass in a value of type String, a compile-time error occurs. This is true whether you are calling a built-in VBA function, a user-defined function, or a DLL function. When you declare an argument as type Any, however, no type-checking occurs, so you should be cautious when passing a value to an argument of this type.

Note   Some DLL functions have an argument that can accept either a string or a null pointer to a string. A null pointer to a string is a special pointer that instructs Microsoft® Windows® to ignore a given argument. It is different from a zero-length string (""). In early versions of VBA, programmers must either declare such an argument as type Any, or declare two versions of the DLL function — one that defines the argument as type String and one that defines it as type Long. VBA now includes the vbNullString constant. This constant represents a null pointer to a string, so you can declare the argument as type String and pass in the vbNullString constant for the case in which you must pass in a null pointer. For more information about passing a null pointer from VBA, search the Microsoft® Developer Network (MSDN®) Web site at https://msdn.microsoft.com/default.asp for the keyword "vbNullString."

See Also

Adding Help to Your Custom Application | Displaying Help by Using the HtmlHelp API | Calling DLL Functions | Argument Data Types | Returning Strings from DLL Functions | Passing User-Defined Types | Retrieving Error Information Following DLL Function Calls