如何从Sharepoint中的同一链接下载多个文件

何塞·M。

我有以下代码可以从共享点站点下载单个文件:

  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


    Dim Ret As Long

    Sub Report_download()

        Dim strURL As String
        Dim strPath As String
        Dim strFile As String

        strFile = "report.Denial." & Format(sDate, "yyyymmdd") & ".xlsx"

        strURL = "https://sharepoint.com/HumanResources/Shared%20Documents/report.Denial.xlsx"
        strPath = sPATH & strFile
        Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)


        If Ret = 0 Then
    '        MsgBox "File successfully downloaded"
        Else
            MsgBox "Returncode:" & Ret & " Unable to download"
        End If

    End Sub

我的问题是这个。我有 3 个文件要从同一个站点下载。链接是相同的,当然,报告名称除外。有没有办法将此代码重写为循环以从此 URL 下载我需要的 3 个文件?

谢谢你

这应该做你想做的。

Option Explicit
Sub btnSharePointFolder()
    Dim sht As Worksheet

    Set sht = ThisWorkbook.Sheets("SharePoint Download")

    If sht.Range("SharePointPath") = "" Then
        MsgBox "Please enter a sharepoint path first", vbCritical
        Exit Sub
    End If

    If Right(sht.Range("SharePointPath"), 1) <> "/" Then
        'SharePointPath: http://testdrive.sharepoint.ckannan.blogspot.com/teams/YourTeam/
       sht.Range("SharePointPath") = sht.Range("SharePointPath") & "/"
    End If

    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = sht.Range("SharePointPath")
        .Title = "Please select a location of input files"
        .Show
        If Not .SelectedItems.Count = 0 Then
            sht.Range("SharepointFolder") = .SelectedItems(1)
        Else
            Exit Sub
        End If
    End With

'    'To Remove Drive
'    Shell "net use Q: /delete"

    If Dir("Q:\", vbDirectory) = "" Then
        Shell "net use Q: " & sht.Range("SharePointPath").Value  '/user:MyDomain\MyUserName MyPassword
   End If

End Sub
'_________________________________________________________________________________
Sub MapNetworkDrive()
    If Dir("Q:\", vbDirectory) = "" Then
    'SharePointPath: http://testdrive.sharepoint.ckannan.blogspot.com/teams/YourTeam/
       Shell "net use Q: " & ThisWorkbook.Sheets("SharePoint Download").Range("SharePointPath").Value  '/user:MyDomain\MyUserName MyPassword
       MsgBox "The sharepoint path is mapped as network drive.", vbInformation
    Else
        MsgBox "The mapped network drive already exists.", vbInformation
    End If
End Sub
'_________________________________________________________________________________
Sub DownloadFiles()
    Dim Directory As String
    Dim file As String
    Dim i As Long
    Dim fso As FileSystemObject

    Application.ScreenUpdating = False

    If Dir("Q:\", vbDirectory) = "" Then
        MsgBox "There is no mapped network drive", vbCritical
        Exit Sub
    End If

    'DownloadFolder: http://testdrive.sharepoint.ckannan.blogspot.com/teams/YourTeam/Shared Documents/PDW Status
   Directory = "Q:\" & ThisWorkbook.Sheets("SharePoint Download").Range("DownloadFolder").Value & "\"
    Set fso = CreateObject("Scripting.FileSystemObject")

'  Get first file
   file = Dir(Directory, vbReadOnly + vbHidden + vbSystem)

    If file = "" Then
        MsgBox "No files found in the sharepoint folder.", vbCritical
        Exit Sub
    End If

    Do While file <> ""
        fso.CopyFile Directory & file, "C:\", True
        file = Dir()
    Loop

    Application.StatusBar = False

    MsgBox "Downloaded all files to the local folder.", vbInformation
End Sub
'_________________________________________________________________________________
Sub btnLocalFolder_Click()
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = "C:\"
        .Title = "Please select a location to download files"
        .Show
        If Not .SelectedItems.Count = 0 Then
            ThisWorkbook.Sheets("SharePoint Download").Range("LocalFolder") = .SelectedItems(1)
        End If
    End With
End Sub

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用wget从各种链接下载多个文件

来自分类Dev

从 href 链接下载文件,如何?

来自分类Dev

从数组中的链接下载文件

来自分类Dev

如何从Python中的链接下载图像?

来自分类Dev

从指向文件的链接下载

来自分类Dev

如何使用Python从Excel导出中的超链接下载文件

来自分类Dev

web.py:如何使超链接下载文件

来自分类Dev

HTML:如何使用链接下载pdf文件

来自分类Dev

如何检查要从链接下载的文件的类型

来自分类Dev

如何使用SVN + ssh链接下载文件?

来自分类Dev

Python通过csv中存储的链接下载文件

来自分类Dev

Python通过csv中存储的链接下载文件

来自分类Dev

Android:如何在Android中创建直接下载链接

来自分类Dev

直接下载链接到OneDrive文件?

来自分类Dev

Mega:共享文件的直接下载链接

来自分类Dev

如何在Java中通过Google Drive API v3获取文件的直接下载链接

来自分类Dev

如何让点击链接下载图片?

来自分类Dev

PHP - 从链接下载pdf文件并保存在本地文件夹中

来自分类Dev

使用wget从共享下载链接下载文件

来自分类Dev

如何使用.bat脚本从非静态链接下载文件

来自分类Dev

如何从Google Drive直接下载链接获取文件扩展名?

来自分类Dev

使用Selenium通过PhantomJS中的超链接下载文件

来自分类Dev

如何保护文件免于直接下载?

来自分类Dev

在Office 365中,如何获得One Drive for Business中存储的Excel文档的直接下载链接?

来自分类Dev

如何在Torrent Trackers中通过UDP链接下载种子

来自分类Dev

如何从多个URL下载同一文件以提高速度?

来自分类Dev

从我的网页内的链接下载文件

来自分类Dev

不通过磁铁链接下载文件

来自分类Dev

从我的网页内的链接下载文件

Related 相关文章

热门标签

归档