vba7中的对象浏览器不显示WebClient对象成员 [英] Object browser in vba7 does not show WebClient Object members

查看:243
本文介绍了vba7中的对象浏览器不显示WebClient对象成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从URI下载并自动保存文件。我想我可以使用urlmon库中的URLDownloadToFile,但是我想使用WebClient.DownloadFile方法。

I need to download and save a file automatically from a URI. I think I can use URLDownloadToFile from "urlmon" library but I wanted to use the WebClient.DownloadFile method.

我希望这是一个cakewalk,但出于我以外的原因,我无法在VBA 7 IDE中查看或使用WebClient类的成员。我已经引用了.Net 2框架的System.tlb,并且可以看到System.Net命名空间中的类,但是许多类的成员都不可见,我不能在我的代码中使用它们。

I hoped it would be a cakewalk but for reasons beyond me, I am not able to view or use the members of the WebClient class in the VBA 7 IDE. I have already referenced the .Net 2 framework's System.tlb and am able to see the classes in the System.Net namespace but members for many of the classes are not visible and I cannot use them in my code.

我尝试使用如下代码时收到编译错误:

I get a compilation error on trying to use a code like:

Dim Downloader as New System.WebClient

Downloader.DownloadFile("uri","filename")

也许我还没有注册在VBA中使用的.Net类,因此也是这个问题。我的项目中引用的 System.dll 位于 C:\Windows\Microsoft.NET\Framework\v2.0.50727 \System.tlb

Maybe I have not registered the .Net classes to be used in VBA and hence the problem but; the System.dll being referred to in my project is located at C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb

这更混淆了我。另外,如果有人可以在VBA 7中详细介绍引用.Net框架库的过程,真的有帮助。

which confuses me even more. Also, it will really help if someone can detail out the process to reference .Net Framework libraries in VBA 7.

提前感谢!

推荐答案

代替.Net库,我建议使用MSXML库。您可以通过点击工具--->引用...并选中Microsoft XML,xx旁边的框,将其添加到IDE中的VBA。其中xx是最新版本。

In lieu of .Net libraries, I suggest using the MSXML library. You can add it to VBA in the IDE by clicking "Tools" ---> "References..." and checking the box next to "Microsoft XML, x.x" where x.x is the most recent version.

这是一个可以运行的快速测试:

Here is a quick test you can run:

Public Sub Downl()
    Dim xhttp As MSXML2.XMLHTTP
    Set xhttp = New MSXML2.XMLHTTP

    Dim oFile As Integer
    oFile = FreeFile()
    Open CurrentProject.Path & "\test.png" For Binary Access Write As oFile

    Dim bdata() As Byte

    With xhttp
        .Open "GET", "https://www.google.com/images/srpr/logo11w.png", False
        .send
        bdata = .responseBody
        Put oFile, 1, bdata
    End With

    Close oFile
End Sub

这篇关于vba7中的对象浏览器不显示WebClient对象成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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