VBA检索具有条件的共享点列表

时间:2018-11-21 19:06:07

标签: excel vba excel-vba sharepoint

以下代码完美地提取了列表。但是,我正在寻找根据条件将其提取的帮助。

Dim objMyList As ListObject
Dim objWksheet As Worksheet
Dim strSPServer As String
Dim strFilter As String
Const SERVER As String = "sharepoint site name"
Const LISTNAME As String = "{XXX-E8AE3D708B81}"
Const VIEWNAME As String = "{XXXC26E71804CE3}"
strSPServer = "https://" & SERVER & "/_vti_bin"
Set objWksheet = Sheet3
strFilter = "apples"
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
Array(strSPServer, LISTNAME, VIEWNAME), False, , Range("b8"))

我还有另一个基于条件提取的代码段。但是,该代码的问题在于,它没有像以前的代码那样将其提取到可同步表中。

Dim strConnection As String
Dim strSQL As String
Dim strFilter As String
strFilter = "apples"
strSQL = "SELECT [FIELDNAME2] FROM list WHERE FIELDNAME =" & Chr(34) & strFilter & Chr(34)
strConnection = "OLEDB; Provider=Microsoft.ACE.OLEDB.12.0; WSS; IMEX=0; RetrieveIds=Yes; DATABASE=MYSHAREPOINTSITE;LIST={XXXXXCE10-4963-B00C-E8AE3D708B81};"

With ActiveSheet.QueryTables.Add(Connection:=Array(strConnection), Destination:=Range("b5"), Sql:=strSQL)

.CommandText = Array(strSQL)
.Name = "Data from SP list"
.FieldNames = True
.PreserveFormatting = True
.BackgroundQuery = True
.Refresh
 End With

我希望有人可以帮助修改第一个代码并添加WHERE子句,或者第二个以表格式获取它,以便一旦完成编辑后就可以同步。

0 个答案:

没有答案