I am getting following error.
Compile error: The code in this project must be updated for use on 64-bit systems.
VBA CODE<
You must be running this on a 64Bit version of Office whereas previously you were using a 32Bit version.
To convert 32Bit calls to 64Bit you generally have to add PtrSafe
to the function and convert some of the data types from Long
to LongPtr
(which is merely a larger datatype (see: http://msdn.microsoft.com/en-us/library/office/gg251378.aspx)
So the converted function would be:
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByRef pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserve As Long, _
ByRef lpfnCB As LongPtr) _
As LongPtr
Edit: Note if you want to be able to use this on both 64Bit and 32Bit versions of Office you need to use a preprocessor If statement so Office knows which function to use. Ie:
#If Win64 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon".......
#Else
Private Declare Function URLDownloadToFile Lib "urlmon".......
#End If
MSDN reference
Complete error message: The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute. All Declare Statements must now include the PtrSafe keyword when running in 64-bit versions of Microsoft Office. The PtrSafe keyword indicates a Declare statement is safe to run in 64-bit versions of Microsoft Office. 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 either LongLong for 64-bit integrals or LongPtr for pointers and handles.
Add the PtrSafe
keyword.