excel 2010从sharepoint列表中获取数据

时间:2013-09-30 21:11:08

标签: excel excel-vba sharepoint-2010 vba

我需要从SharePoint列表中获取数据。我遇到了下面的代码,我尝试了许多不同的网址组合等。 但我一直在

  

“运行时错误1004”“应用程序定义或对象定义错误”

我拥有该网站的完全管理员权限 我正在使用SharePoint 2010和Excel 2010

这里是我找到的代码:

Sub ImportSharePointList()
    Dim objMyList As ListObject
    Dim objWksheet As Worksheet
    Dim strSPServer As String
    Const SERVER As String = "xxx.xxx.net/sites/tss_PP/Lists"
    Const LISTNAME As String = "{F915A40C-0394-418C-AB90-xxxxxxxxxxxxx}"
    Const VIEWNAME As String = ""
   ' The SharePoint server URL pointing to
   ' the SharePoint list to import into Excel.
    strSPServer = "https://" & SERVER & "/_vti_bin"
    ' Add a new worksheet to the active workbook.

    Set objWksheet = ActiveSheet


     Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
        Array(strSPServer, LISTNAME, VIEWNAME), True, , Range("A2"))

    Set objMyList = Nothing
    Set objWksheet = Nothing
End Sub

任何帮助都会很棒,只是我在使用和不使用视图名称的情况下尝试了这个注释

1 个答案:

答案 0 :(得分:1)

如果我将变量设置如下,那么您的代码在此处运行良好(Excel 2010,SHP-2007):

Const SERVER As String = "shp.myserver.myorg/sites/[mainsite]/[subsite]"
Const LISTNAME As String = "Country" ' real List name
Const VIEWNAME As String = ""

服务器:我不包括/ List或任何其他后缀,只包括子网站级别

enter image description here