1

我希望能够在 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
4

2 回答 2

2

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

于 2012-10-29T15:46:52.660 回答
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)
于 2013-04-24T11:05:46.290 回答