使用文档列表中的子文件夹维护Sharepoint Server Url

时间:2015-06-09 08:24:20

标签: excel vba excel-vba sharepoint listobject

我想遍历Sharepoint文档库项目(文件和文件夹以及子文件夹),然后在Excel工作表中打印每个文件夹内容

我的宏中有以下代码

Sub WriteFileProp(mySourcePath As String)

    Dim objMyList As ListObject
    Dim objWksheet As Worksheet
    Dim strSPServer As String
    Dim SERVER As String
    Const LISTNAME As String = "Documents"
    Const VIEWNAME As String = ""
     SERVER = mySourcePath
   ' The SharePoint server URL pointing to
   ' the SharePoint list to import into Excel.

    strSPServer = "http:" & SERVER & "/_vti_bin"
    ' Add a new worksheet to the active workbook.
    Set objWksheet = Worksheets.Add
    ' Add a list range to the newly created worksheet
    ' and populated it with the data from the SharePoint list.
    Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
        Array(strSPServer, LISTNAME, VIEWNAME), False, , Range("A1"))

 End Sub

和那个功能

 Dim objFSO As Object
 Dim objFolder As Object
 Dim ObjFile As Object
 Dim SubFolder As Object
 Dim pth As String
 Dim WBn As Workbook
 Dim ObCount As Long
 Dim FileNme As String

 Application.ScreenUpdating = False

 Set objFSO = CreateObject("Scripting.FileSystemObject")

 'Get the folder object associated with the directory
 Set objFolder = objFSO.GetFolder("//S1.S2.S3Portal/Shared%20Documents/")

 Call WriteFileProp("S1.S2.S3Portal.com/")
 'Print main view

For Each SubFolder In objFolder.SubFolders
            Call WriteFileProp(SubFolder.Path)
        Next

一切正常,直到Call WriteFileProp("S1.S2.S3Portal.com/") 之后,我循环子文件夹,路径不兼容

中提供的ServerUrl
objWksheet.ListObjects.Add(xlSrcExternal, _
        Array(strSPServer, LISTNAME, VIEWNAME), False, , Range("A1"))

即。假设第一个子文件夹名称是Software,其路径采用以下格式 //S1.S2.S3Portal/Shared%20Documents/Software

但ListObjects.Add仅接受msdn

的格式

strSPServer = http://S1.S2.S3Portal

ListName =“Documents”

观看=“”

无论如何都要维护该文档的子文件夹。库并使用ListObjects.Add或类似函数将它们添加到excel工作簿

1 个答案:

答案 0 :(得分:0)

我已经使用带有Soap查询和webservice的GetListItem来获取列表项而不是发布的方法