Microsoft Office 2000/Visual Basic Programmer's Guide   

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 allows you to pass any data type to this argument. However, the DLL function may be designed to accept only two or three different types of data, so passing in the wrong type of data may cause an application error.

Normally when you compile your code in a VBA project, VBA performs type-checking on the values that you pass for each argument. That is, it ensures that 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 holds true whether you're 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 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, which represents a null pointer to a string, so that you can declare the argument as type String, and pass in the vbNullString constant for the case in which you need to pass in a null pointer. For more information about passing a null pointer from VBA, search the Microsoft Developer Network site at http://msdn.microsoft.com/developer/ for the keyword "vbNullString."

For an example of a DLL function that uses the Any data type, see the section "Displaying Help by Using the HtmlHelp API" in Chapter 13, "Adding Help to Your Custom Solution."