gpt4 book ai didi

excel - 如何使用VBA从SharePoint下载文件?

转载 作者:行者123 更新时间:2023-11-28 03:33:46 27 4
gpt4 key购买 nike

我正在尝试使用 VBA 从 SharePoint 下载文件。

该文件是一张图片,但该图片一旦进入系统就无法查看。

我认为我下载的格式错误。

Sub DownloadFromSharepoint()
Dim myURL As String
myURL = "https://MYSHAREPOINTSITE"

Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send

If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.ResponseBody
oStream.SaveToFile ("C:\Users\DOMAIN\temp.jpg")
oStream.Close
End If
End Sub

最佳答案

以下是我当前用于从 Sharepoint 站点下载文件的包装器代码:

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

Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long
' strSavePath includes filename
DownloadFileFromWeb = URLDownloadToFile(0, strURL, strSavePath, 0, 0)
End Function

如果下载成功,函数 DownloadFileFromWeb 返回 0。

关于excel - 如何使用VBA从SharePoint下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57923955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com