1

My code worked fine in excel 2010 version but I am not sure what am I need to change in 2013 version.

Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Dim Ret As Long

'~~> This is where the images will be saved. Change as applicable
Const FolderName As String = "C:\Temp\"
pnuts
  • 58,317
  • 11
  • 87
  • 139
user206168
  • 1,015
  • 5
  • 20
  • 40
  • PS. Never hard code `C:\Temp`. At least use `Environ$("temp")` or some other standard way like with a `FileSystemObject` class. See this answer http://stackoverflow.com/a/26530127/380384 – John Alexiou Oct 16 '15 at 20:12

1 Answers1

2

I tend to convert these types of functions to ones that are PTRSafe:

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As LongPtr
Dim Ret As LongPtr

This consists of adding the word "PtrSafe" and changing all "Long" variables to LongPtr

Demetri
  • 869
  • 1
  • 6
  • 12
  • Thanks that worked... can you please explain why does it fix with PTRSafe and what does it do? – user206168 Oct 16 '15 at 20:06
  • It does nothing. It just forces you to acknowledge that you have reviewed the code and it is now 64-bit safe. Is it like the *`new`* gifs people use to put next to updated items in the days of HTML 1.0 – John Alexiou Oct 16 '15 at 20:15
  • Full details of `PtrSafe` and the other 64-bit changes are [here](https://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx#odc_office2010_Compatibility32bit64bit_ApplicationProgrammingInterfaceCompatibility) – barrowc Oct 16 '15 at 23:06