我收到以下错误。Excel 2013 VBA错误
Compile error: The code in this project must be updated for use on 64-bit systems.
VBA代码
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\"
它工作正常,在Excel 2010中
感谢。
编辑
错误我得到的是Ret Variable Not defined
。这是代码的其余部分。
Sub Sample()
Dim ws As Worksheet
Dim LastRow As Long, i As Long
Dim strPath As String
'~~> Name of the sheet which has the list
Set ws = Sheets("Sheet1")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow '<~~ 2 because row 1 has headers
strPath = FolderName & ws.Range("A" & i).Value & ".mp3"
Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, strPath, 0, 0)
If Ret = 0 Then
ws.Range("C" & i).Value = "File successfully downloaded"
Else
ws.Range("C" & i).Value = "Unable to download the file"
End If
Next i
End Sub
非常感谢,但我也应该添加其他代码。我之前得到的错误是修复感谢,但我得到错误,'Ret'变量未定义。 – Mowgli
没有probs。您还需要将'Ret'变量从'Long'转换为'LongPtr',因为这是该函数的新返回类型。 (如果它是一个全局变量,那么使用'Public'(或'Private'作为该模块)而不是'Dim') – CuberChase
嗨,对不起,我刚刚有时间。但我尝试添加LongPtr,并尝试公开但它没有工作。我该怎么办?谢谢 – Mowgli