当仅输入URL时,VBA中是否有一种方法可以从Sharepoint列表中获取ListName参数?

时间:2019-01-08 19:05:17

标签: excel vba sharepoint sharepoint-2010

我正在VBA中构建一个对Sharepoint数据进行操作的工具。我不知道如何处理列表。我希望能够使用宏的列表URL将列表下载为表格(就像在Web查询.iqy中一样)。

我在Objective-c中找到了有关此内容的较早文章: Sharepoint: GetList listName returning all list

但是我不知道如何在VBA中做到这一点。我希望可以在没有太多标记语言的情况下完成此操作。也许发送一种查询到共享点站点并检索参数(使用WinHttp.WinHttpRequest)。 该功能将利用以下代码。不幸的是,我可以从URL中提取Server和ViewGUID,但不能提取ListName。

Sub ImportSharePointList()

    Dim objMyList As ListObject
    Dim objWksheet As Worksheet
    Dim strSPServer As String
    Const SERVER As String = "mysite:8003/sites/the-sharepoint-thing/"
    Const LISTNAME As String = "{D1F1C2ED-81BA-41CC-A698-XXXXXXXXXXXX}"
    Const VIEWNAME As String = "{27C9CA20-3293-4BD5-9271-XXXXXXXXXXXX}"

   ' 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

1 个答案:

答案 0 :(得分:0)

我能够实现的是构建一个对sharepoint API的http查询:

...
myUrl = [the address.aspx]

With theHttp
    .SetAutoLogonPolicy(AutoLogonPolicy_Always)
    .Open "GET", myUrl, False
    .Send
    resp = .ResponseText
End with
...

然后我只是使用Mid来取出ListId。 该查询从站点检索了所有数据(太多)。有人可以告诉我如何只检索ListId吗?