
- #VISUAL BASIC FOR APPLICATIONS OFFICE 365 HOW TO#
- #VISUAL BASIC FOR APPLICATIONS OFFICE 365 CODE#
- #VISUAL BASIC FOR APPLICATIONS OFFICE 365 DOWNLOAD#
- #VISUAL BASIC FOR APPLICATIONS OFFICE 365 WINDOWS#
On 64-bit Office, this is incorrect because the pointer needs to be 64-bits. The modified VBA example contains the PtrSafe qualifier, but notice that the return value (a pointer to the active window) returns a Long data type. Running the unmodified Declare statement in 64-bit versions of Office will result in an error indicating that the Declare statement does not include the PtrSafe qualifier. To ensure backwards compatibility in VBA7 and earlier use the following construct: #If VBA7 ThenĬonsider the following Declare statement examples. Declare statements that include PtrSafe work correctly in the VBA7 development environment on both 32-bit and 64-bit platforms. The PtrSafe keyword asserts that a Declare statement is safe to run in 64-bit versions of Office.ĭeclare statements with the PtrSafe keyword is the recommended syntax. Implicit conversions of LongLong to smaller integrals are not allowed. Conversion functions must be used to explicitly assign LongLong (including LongPtr on 64-bit platforms) to smaller integral types. The LongLong data type is a signed 64-bit integer that is only available on 64-bit versions of Office. The actual data type that LongPtr resolves to depends on the version of Office that it is running in LongPtr resolves to Long in 32-bit versions of Office, and LongPtr resolves to LongLong in 64-bit versions of Office. VBA now includes the variable type alias LongPtr. Three important additions are the LongPtr type alias, the LongLong data type, and the PtrSafe keyword. The table at the bottom of this document summarizes the new VBA language features.
#VISUAL BASIC FOR APPLICATIONS OFFICE 365 CODE#
To address this problem and enable VBA code to work correctly in both 32-bit and 64-bit environments, several language features have been added to VBA. This can result in memory overruns, unexpected results in your code, and possible application failure. The problem with running legacy VBA code in 64-bit Office is that trying to load 64-bits into a 32-bit data type truncates the 64-bit quantity.

#VISUAL BASIC FOR APPLICATIONS OFFICE 365 WINDOWS#
That is not surprising, since with VBA you can code pretty much any desktop application, if you don’t mind it running within Office, undermining Microsoft’s intention that only Windows Runtime (formerly known as Metro) apps can be installed on Windows RT.You only need to modify VBA code if it runs in the 64-bit version of Microsoft Office. I have not yet seen Office running on ARM in Windows RT, but the rumour is that VBA is not supported. You are giving up the safety of VBA once you use these functions. Note that if you get it wrong VBA and Office may crash.
#VISUAL BASIC FOR APPLICATIONS OFFICE 365 HOW TO#
It can still be difficult to work out how to call some APIs. The file is too large to load into a single VBA module but you can use it to find the declarations that you need.
#VISUAL BASIC FOR APPLICATIONS OFFICE 365 DOWNLOAD#
The file is called Win32API_PtrSafe.txt and you can download it here. What that article does not mention though is that Microsoft has provided declarations for the most commonly used API declarations that work in both 32-bit and 64-bit VBA. Without PtrSafe, the Declares will not execute in 64-bit Office.

Still, it means you have to add PtrSafe to all your Declares, the idea being that you check that they work. In fact it does nothing at all other than to say to the compiler that the Declare works in 64-bit Office, whether or not it really does. The name of this attribute is dubious in that it does nothing to ensure pointer safety.

Some existing Declare statements will work fine on both platforms, but Microsoft chose to force developers to review all of them by introducing a new PtrSafe attribute. One implication though is that code written for 32-bit VBA may need revising to work in 64-bit Office, and I ran into this recently with some VBA code of my own. Visual Basic makes it easy to call the Windows API though the Declare statement. It is based on the same runtime that powers Visual Basic 6.0, the last version before the. The version is Office 2010 is 7.0.Īlthough it is embedded in Office, VBA is a powerful tool and there is not much that you cannot do. In fact, Visual Basic for Applications (VBA) has been slightly updated, and reports itself as version 7.1 in the preview. The first macro programming language in Microsoft Office was Basic, and it is still there in the forthcoming Office 2013.
