#vba #list #sharepoint
Вопрос:
Я создал список «Присоединиться к sharepoint» в VBA с помощью ADO. Мои объединения в значительной степени работают, когда у меня есть 2 или три списка, но я не работаю со списком из 4 или 5. Я думаю, что есть проблема с запятой, но я не понимаю ошибки в своем соединении.
Не могли бы вы мне помочь?
S
ub Import_List()
Dim sp_sdbPath As String, sp_sConnect As String
Dim SP_List_1 As String, SP_List_2 As String, SP_List_3 As String
Dim icolumn As Long
Dim cnSP As New ADODB.Connection
Dim rsSP As New ADODB.Recordset
sp_sdbPath = "https://test"
sp_sConnect = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes;DATABASE=" amp; sp_sdbPath amp; ";"
SP_List_2 = "LIST= {6576BDBD-6CE3-4BB4-8680-3F68BD2E9296}"
SP_List_1 = "LIST={6576BDBD-6CE3-4BB4-8680-3F68BD2E9296}"
SP_List_3 = "LIST={CCF64A7C-3421-461A-A6C8-4AC014DFC27E}"
SP_List_4 = "LIST={7739C5DE-F4CD-402A-9747-B239B203500D}"
SP_List_8 = "LIST={AE2EEB78-7984-4488-8EBD-513458C04F9A}"
'Establish a connection to the first List
cnSP = sp_sConnect SP_List_1
cnSP.Open
'Write the SQL amp; Establish a connection to the second List as a sub-query using IN
sSQL = "SELECT *" _
"FROM (List [List_1]" _
"INNER JOIN *(*Select * From LIST IN 'DATABASE=" amp; sp_sdbPath amp; ";" amp; SP_List_2 amp; "' 'WSS;RetrieveIds=Yes;') [List_2] On [List_1].[ID] = [List_2].[ID])" _
"INNER JOIN (Select * From LIST IN 'DATABASE=" amp; sp_sdbPath amp; ";" amp; SP_List_3 amp; "' 'WSS;RetrieveIds=Yes;') [List_3] On [List_1].[ID] = [List_3].[ID]" _
"INNER JOIN (Select * From LIST IN 'DATABASE=" amp; sp_sdbPath amp; ";" amp; SP_List_4 amp; "' 'WSS;RetrieveIds=Yes;') [List_4] On [List_1].[ID] = [List_4].[ID]" _
"INNER JOIN (Select * From LIST IN 'DATABASE=" amp; sp_sdbPath amp; ";" amp; SP_List_5 amp; "' 'WSS;RetrieveIds=Yes;') [List_5] On [List_1].[ID] = [List_5].[ID]" _
rsSP.Open sSQL, cnSP, adOpenStatic, adLockReadOnly 'Change cursor amp; lock type if inserting, updating or deleting
'The rest is to drop the results into an empty worksheet named 'Test'
For icolumn = 0 To rsSP.Fields.Count - 1
ThisWorkbook.Sheets("SrcMSP-Prestations").Cells(1, icolumn 1) = rsSP.Fields(icolumn).Name
Next
ThisWorkbook.Sheets("SrcMSP-Prestations").Cells(2, 1).CopyFromRecordset rsSP
If rsSP.BOF Then
CreateTimeSheet = False
Else
CreateTimeSheet = True
End If
rsSP.Close
cnSP.Close
End Sub