无法使用Excel中的ADODB连接到SharePoint网站

时间:2012-10-01 14:00:48

标签: sharepoint excel-vba vba excel

我希望能够在excel中创建一个adodb记录集,我可以根据需要循环进行添加/编辑等。以下内容创建记录集但引发错误(80004005)“无法连接到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

2 个答案:

答案 0 :(得分:2)

虽然您不应该直接访问SQL Server数据库,但问题中描述的技术不违反此规则。所描述的技术使用类似SQL的API来查询列表。您会注意到查询未引用实际的SQL Server表。

答案 1 :(得分: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)