vba Access 2010 中的 UrlDownloadToFile - 未定义子或函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26186279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UrlDownloadToFile in Access 2010 - Sub or Function not Defined
提问by danjfoley
I am trying to use the function URLDownloadToFile in Access 2010 VBA code. When i run the code it tells me that URLDownloadToFile is not defined.
我正在尝试在 Access 2010 VBA 代码中使用 URLDownloadToFile 函数。当我运行代码时,它告诉我未定义 URLDownloadToFile。
I have read that this function is in the urlmon.dll which i DO have on my computer. I tried to click the references button in the code editor and load it but it would not let me do so.
我已经读到这个函数在我电脑上的 urlmon.dll 中。我试图单击代码编辑器中的引用按钮并加载它,但它不允许我这样做。
How can I fix this so I can use the function? Or is there another function that will allow me to download a url to to a file?
我该如何解决这个问题,以便我可以使用该功能?或者是否有另一个功能可以让我将 url 下载到文件?
回答by David Zemens
You'll need to declare this WinAPI function in order to call it from procedures in your code.
您需要声明此 WinAPI 函数,以便从代码中的过程调用它。
From HERE
从这里
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
Public 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
If Dir(LocalFileName) <> vbNullString Then
DownloadFile = True
End If
End If
End Function
Private Sub Form_Load()
If Not DownloadFile("http://www.ex-designz.net", "c:\photogallery.asp") Then
MsgBox "Unable to download the file, or the source URL doesn't exist."
End If
End Sub