These constants can be use with the commands #IF, #ElseIf, #Else and #End IF.įor example the following code for getOSType macro will return “Windows” or “Mac” (or “Unknown”) depending on the machine type:
And the relevant compiler constants are Mac, Win64, Win32 respectively.
In this case, we want to know is the machine is running a MacOS, Windows 64 bit or Windows 32 bit. The VBA compiler includes constants that are set to true or false depending on the Operating System. Microsoft provides development-time and run-time methods to figure out the environment and change the code or the behavior accordingly.Īs a first step let’s review the development-time ability. In a broad generalization, every time there is a reference to external resources, such as access to the file system (paths are different) or reference to DLLs (no DLLs) the macros will fail and sometimes the VBA code will not even compile. Recently I’ve moved to Mac and discovered that some of the Macros i’ve used for years are not designed for the Mac environments. However, till now it was done on Windows based machines only. Most of my professional life I’ve worked with fairly complex Excel files with many macros. Excel Workbooks with Macros are powerful.