When using Windows API functions in your procedure, it is necessary to ensure compatibility of your code with the 32-bit and 64-bit versions of Excel. To do so, you need to declare two versions of API functions using conditional compiler directives.
Bitness is defined as "A characteristic of a microprocessor's data stream (the distinction between 16-bit, 32-bit and 64-bit address spaces) and the potential differences in instantiation of components that this entails"
With the release in Windows 7, 64-bit machines grow significantly and API functions compatible with 64-bit machines are available and need to be discerned from 32-bit API functions.
To determine whether you have 32 or 64 bit Windows, open the Control Panel and then the System item. The "System Type" element will indicate whether your computer is capable of 64 bit Windows and whether 64 bit Windows is in fact installed. 64-Bit Office can be run only on 64-bit Windows computers. If you have 32-bit Windows, then you have 32-bit Office.
To ensure compatibility of your code with both 32-bit and 64-bit Excel, it is necessary to declare two versions of the function by using conditional compiler directives with # as prefix.
'for 64-bit Excel 2010 and later
#If VBA7 And Win64 Then
Declare PtrSafe Function GetWindowsDirectoryA Lib "kernel32" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
#Else
Declare Function GetWindowsDirectoryA Lib "kernel32" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
#End If
Dated on: 13-Mar-2019