Table of contents
Collapse the table of content
Expand the table of content


office 365 dev account|Last Updated: 6/12/2017
1 Contributor

The PtrSafe keyword is used in this context:

Declare Statement

Note Declare statements with the PtrSafe keyword is the recommended syntax. Declare statements that include PtrSafe work correctly in the VBA7 development environment on both 32-bit and 64-bit platforms only after all data types in the Declare statement (parameters and return values) that need to store 64-bit quantities are updated to useLongLong for 64-bit integrals orLongPtr for pointers and handles. To ensure backwards compatibility with VBA version 6 and earlier use the following construct:

#If VBA7 Then 
Declare PtrSafe Sub... 
Declare Sub... 

When running in 64-bit versions of Office Declare statements must include the PtrSafe keyword. The PtrSafe keyword asserts that a Declare statement is safe to run in 64-bit development environments. Adding the PtrSafe keyword to a Declare statement only signifies the Declare statement explicitly targets 64-bits, all data types within the statement that need to store 64-bits (including return values and parameters) must still be modified to hold 64-bit quantities using eitherLongLong for 64-bit integrals orLongPtr for pointers and handles.

© 2018 Microsoft