2013-09-30 65 views
1

我需要從SharePoint列表中獲取數據。我碰到下面的代碼,我已經嘗試過的網址等 的許多不同的組合,但我不斷收到excel 2010從分享點列表中獲取數據

「運行時錯誤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

您的代碼工作得很好這裏(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 = "" 

服務器:我不包括/列表或任何其它後綴,只能下到子網站級別

enter image description here