How to use Windows SHBrowseforFolder function on 32 bit or 64 bit Excel VBA

I have a module ("Module1.bas") in which conditional compilation constants are used as a programmatic test to determine the VBA version number (e.g. VBA7) and whether or not it's operating on a 64 bit platform. Based on the result of that test, a Private type "BROWSEINFO" is declared as is the Windows API function SHBrowseforFolder which varies between the 32 and 64 bit types. In the 32 bit version it returns a Long, whereas in the 64 bit version it returns a LongPtr.

That's working just fine.

However, in the same module, there is a function, "GetDirectory" which uses the datatype and SHBrowseforFolder function from the declaration mentioned above....except in this function, the return types are declared at the start of the GetDirectory function as Long and are thus "hard coded". There doesn't seem to be any way of making the data type of these conditional on the VBA version and OS type.

Have I missed something here?

I'd REALLY like to be able to get the VBA to run depending on which Excel version it runs on instead of having 2 different versions.

Read more here:

Content Attribution

This content was originally published by Rob Barrow at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: