Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA/.Net通过Windows Security从受密码保护的网站下载文件_Vba_Excel_Azure_Sharepoint - Fatal编程技术网

VBA/.Net通过Windows Security从受密码保护的网站下载文件

VBA/.Net通过Windows Security从受密码保护的网站下载文件,vba,excel,azure,sharepoint,Vba,Excel,Azure,Sharepoint,我有一个SharePoint测试网站(Azure SharePoint farm),其中包含几个图像文件和一些文档模板。我想将图像下载到本地驱动器。我预计会循环浏览URL列表,例如,依次下载每个URL。我尝试过URLDowloadToFile,如果我把图片放在一个普通的网站上,效果会很好,但我无法通过这种方法通过Windows安全 我尝试过创建InternetExplorer.Application对象(后期绑定),可以查看我的图片,但无法下载。正在尝试ieApp.ExecWB,但这会引发错误

我有一个SharePoint测试网站(Azure SharePoint farm),其中包含几个图像文件和一些文档模板。我想将图像下载到本地驱动器。我预计会循环浏览URL列表,例如,依次下载每个URL。我尝试过URLDowloadToFile,如果我把图片放在一个普通的网站上,效果会很好,但我无法通过这种方法通过Windows安全

我尝试过创建InternetExplorer.Application对象(后期绑定),可以查看我的图片,但无法下载。正在尝试ieApp.ExecWB,但这会引发错误

我还尝试了WinHTTP.WinHTTPrequest.5.1(),但是,尽管这看起来很有希望,但它返回了一个短字符串“???????”而不是图像

我真的希望有一个VBA解决方案,我想知道模拟用户是否可以提供选项,或者是否有其他选项(不包括使用SendKeys)。可悲的是,我正在突破VBA知识的极限,我真的需要一些指导

可以从VBA的共享点下载吗?
如果是这样,我怎么会错过一些简单的东西呢


我可以粘贴代码,但我真的不确定我有什么值得分享的。如果这在VBA中不可能或不可靠,那么在VB.Net(我的下一个最陡峭的学习曲线)中也是可能的。

希望这对其他人有所帮助。我最终使用Visual Studio在VB.Net中创建了一个dll,我可以从VBA调用它。VB.Net dll需要对microsoft.sharepoint.client的引用

VBA代码需要对结果dll的引用

Imports Microsoft.SharePoint.Client

Module Module1
    Sub Main()
        Dim myContext As Microsoft.SharePoint.Client.ClientContext
        myContext = New ClientContext("http://TestSP-a.cloudapp.net/sites/Images/")

        Dim myCredentials As New System.Net.NetworkCredential
        '' I'm accessing a website from the outside so there
        '' are no credentials on my PC. If on the same NW I 
        '' assume I can use the line below instead of the 
        '' 3 lines that follow.
        'myCredentials = System.Net.CredentialCache.DefaultNetworkCredentials
        myCredentials.UserName = "UserNameForSharePoint"
        myCredentials.Password = "PassWordForSharePoint"
        myCredentials.Domain = ""   ' <-- Leave Blank


        Dim mySiteSP As New Uri("http://TestSP-a.cloudapp.net/sites/Images/Image1.png")
        Dim myTemp As String = "C:\temp\test.png"
        My.Computer.Network.DownloadFile(mySiteSP, myTemp, myCredentials, True, 600000I, False)


    End Sub

End Module
导入Microsoft.SharePoint.Client
模块1
副标题()
将myContext设置为Microsoft.SharePoint.Client.ClientContext
myContext=新客户端上下文(“http://TestSP-a.cloudapp.net/sites/Images/")
将myCredentials设置为新System.Net.NetworkCredential
“”我正在从外部访问一个网站,所以
“”在我的电脑上没有凭据。如果在同一台电脑上
“”假设我可以使用下面的行而不是
“”后面的3行。
'myCredentials=System.Net.CredentialCache.DefaultNetworkCredentials
myCredentials.UserName=“UserNameForSharePoint”
myCredentials.Password=“PassWordForSharePoint”
myCredentials.Domain=”“'