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

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

问题描述

我想使用的功能URLDownloadToFile在Access 2010 VBA code。当我运行code它告诉我,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中。我试着点击code编辑器中的引用按钮,加载它,但它不会让我这样做。

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.

我怎样才能解决这个问题,所以我可以使用的功能?还是有另一种功能,将让我一个网址下载到一个文件?

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?

推荐答案

您需要,以便从程序调用它在你的code声明此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

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

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