I have observed an issue with below function call when we migrated to office 2010-64 bit version.
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
According to information available on http://msdn.microsoft.com/en-us/library/ee691831.aspx link. I have changed above call as below and it has been working fine on office 2010 64 bit version.
Private Declare PtrSafe Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
The problem is, I need to make same call to work on older office versions as well and it throws compile error on older versions.
Has anyone any idea how to make this call working for office 2010 and older office versions.
I find the use of this VBA7 compiler constant all over the Internet in relation to Office 64-bit compatibility but contrary to what is often said, this compiler constant detects Office installs using VBA7 e.g. Office 2010 onwards, not 64-bit Office. Confusingly, if you need to determine if you're using the 64-bit version of Office application, you need to use the Win64 constant!
Try this out of 32 and 64 bit versions of Office and you can see what I mean:
Thanks to Steve Rindsberg for putting me straight on this one! Steve also added:
So this should be the correct approach for combining VBA7 and 64-bit Office compatibility:
As the MSDN article says, use conditional compilation: it works well for me in Excel 97 through Excel 2010 32-bit & 64-bit.
Refining the excellent info/answer from Jamie Garroch (which explains how the VBA7 compiler constant doesn't tell you for sure if your code is running in a 64-bit Office application), the VBA compiler's
#if
directive can handleAnd
operators.That means you don't need to repeat your 32-bit function declarations. You can simply do this: