2012-10-01 78 views
1

我希望能夠在excel中創建一個adodb記錄集,並根據需要循環添加/編輯等。下面創建一個記錄,但引發錯誤(80004005)在最後一行「無法連接到SharePoint站點請稍後再試。」:無法使用excel中的ADODB連接到SharePoint網站

strLURL = "<SharePoint list URL>" 
    strGUID = "{D16F31E9-41F3-4193-8926-35FFC0714C86}" 
    intIMEX = 1 
    strList = "Planner" 
    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;" 
    strConn = strConn & "IMEX=" & intIMEX & ";" 
    strConn = strConn & "RetrieveIds=Yes;" 
    strConn = strConn & "DATABASE=" & strLURL & ";" 
    strConn = strConn & "LIST=" & strGUID & ";" 
    strConn = strConn & "VIEW=; RetrieveIds=Yes;" 
    strConn = strConn & "Table = " & strList 

    Dim cnCur As New ADODB.Connection 
    Dim rsCur As New ADODB.Recordset 
    Dim strSQL As String 

    cnCur.Open ConnectionString:=strConn 
    strSQL = "SELECT * FROM [" & strList & "]" 
    rsCur.Open Source:=strSQL, ActiveConnection:=cnCur 

回答

1

我無法使用ADODB連接找到解決方案。相反,我用於與listobjects工作方法 - 這是很簡單:

'Declare variables 
Dim lo as ListObject 
Dim ws as Worksheet 
Dim sServerName As String 'site address e.g "http://yoursite.com/_vti_bin/" 
Dim sName As String 'list id e.g {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 
Dim sGUID As String 'view GUID e.g {yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy} 


'Create listobject 
Set lo = ws.ListObjects.Add(_ 
     SourceType:=xlSrcExternal, _ 
     Source:=Array(sServerName, sName, sGUID), _ 
     Destination:=Range("A1") _ 
     ) 

'Do something with your listobject here 

'Push updates back to server 
lo.UpdateChanges (xlListConflictDialog) 
2

雖然這是事實,你不應該直接訪問SQL Server數據庫,在問題中描述的技術不違反這個規則。所描述的技術使用類似SQL的API來查詢列表。您會注意到查詢沒有引用實際的SQL Server表。

+0

這是不是一個真正的anwser,有足夠的[代表](http://stackoverflow.com/faq#reputation),你會能夠發表對其他答案的評論。 – Jack

+0

這是什麼類型的API?你能指點我描述這種訪問SharePoint列表的任何文檔嗎? –