I'm trying to run a macro in Excel 64-bit that downloads an image file linked in cell C2 with the file name in cell B2, and spits it out onto my desktop. But the three lines of code for the URLDownloadToFile function at the top are highlighted in red in the VBA editor. Why isn't excel allowing me to run that URLDownloadToFile function?
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
Sub getJPGfromweb()
Dim strJPGLink As String
Dim strJPGFile As String
Dim Result As Boolean
strJPGLink = ActiveSheet.Range("C2").Value
strJPGFile = ActiveSheet.Range("B2").Value
Result = DownloadFile(strJPGLink, strJPGFile)
MsgBox Result
End Sub
Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function