从SharePoint下载XLSM文件

发布于 2025-02-08 03:32:44 字数 1381 浏览 2 评论 0原文

我正在使用解决方案的代码

它在我的目标文件夹上生成一个文件,但我无法使用它。它似乎是腐败的。

我是否将文件链接到错误下载?

还是该问题是XLSM文件未设计的XLSM文件?


Option Explicit
#If VBA7 Then
    Private Declare PtrSafe 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
#Else
    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
#End If

    Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long

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


Sub GetFile()
    Dim urlName  As String
    urlName = "https://talanx.sharepoint.com/:x:/r/sites/LiabilityGlobalRisk/_layouts/15/Doc.aspx?sourcedoc=%7BC39E3D22-D263-4519-B6A5-33B64496F6E0%7D&file=Test.xlsm&action=default&mobileredirect=true"
    Dim fName As String
    fName = "J:\TEST\Test.xlsm"
    URLDownloadToFile 0, urlName, fName, 0, 0

End Sub

I am using the codes provided by Solution to download sharepoint xlsx

It generates a file on my destination folder, but I am not able to use it. It seems to be corrupt.

Do I link the file to download wrongly?

Or is the issue an xlsm file for which the code was not designed?


Option Explicit
#If VBA7 Then
    Private Declare PtrSafe 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
#Else
    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
#End If

    Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long

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


Sub GetFile()
    Dim urlName  As String
    urlName = "https://talanx.sharepoint.com/:x:/r/sites/LiabilityGlobalRisk/_layouts/15/Doc.aspx?sourcedoc=%7BC39E3D22-D263-4519-B6A5-33B64496F6E0%7D&file=Test.xlsm&action=default&mobileredirect=true"
    Dim fName As String
    fName = "J:\TEST\Test.xlsm"
    URLDownloadToFile 0, urlName, fName, 0, 0

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文