Access 2010 中的 UrlDownloadToFile - 未定义子或函数 [英] UrlDownloadToFile in Access 2010 - Sub or Function not Defined

查看:31
本文介绍了Access 2010 中的 UrlDownloadToFile - 未定义子或函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Access 2010 VBA 代码中使用 URLDownloadToFile 函数.当我运行代码时,它告诉我未定义 URLDownloadToFile.

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.

我读到这个函数在我电脑上的 urlmon.dll 中.我试图单击代码编辑器中的引用按钮并加载它,但它不允许我这样做.

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.

我该如何解决这个问题,以便我可以使用该功能?或者是否有其他功能可以让我将 url 下载到文件中?

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?

推荐答案

您需要声明此 WinAPI 函数,以便从代码中的过程调用它.

You'll need to declare this WinAPI function in order to call it from procedures in your code.

来自这里

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

这篇关于Access 2010 中的 UrlDownloadToFile - 未定义子或函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆