曾经在“ Excel VBA Sharepoint删除列表”和“ Excel VBA Sharepoint删除列表”上进行了大量的Google搜索。我收到的大多数点击似乎都是关于将项目添加或同步到SharePoint列表。
我发现了一个有关删除列表并上传完整的新列表的结果(这是我想做的),但它表明虽然可以做到,但问题是新列表的GUID与即使它们使用相同的名称,也不会显示先前的列表。
我当前的流程是:
第4步中的所有内容似乎都可以使用,并且只要Sharepoint中以前不存在该列表,第4步都可以使用。
因此,既然我以前创建了这些共享点列表,该如何删除所有内容?后续问题将是我现在如何从excel上传新表?第二部分可能会遍历搜索时发现的所有添加项链接,但我想从第一步开始,即删除上一个列表的内容。我包括第二部分,因为它可能会影响人们对我去向的回答。
当前发布代码:
Sub PublishList(ListName As String, HeaderRow As Long, LastRow As Long, LastCol As Long)
'Converts an excel range to a table/list and
'creates a new SharePoint list and fills it
'with the information from the excel table
Dim spList As ListObjects
Dim newSPList As ListObject
Set spList = ActiveSheet.ListObjects
'converts Excel data in a specified range to a list
Set newSPList = spList.Add(xlSrcRange, Range(Cells(HeaderRow, 1), Cells(LastRow, LastCol + 1)), True, xlYes)
'define the name of the new list/table in excel
newSPList.Name = "IndexTable"
'sends the excel list to defined sharepoint site
'and provided sharepoint list name
newSPList.Publish Array("http://my.company.com/subsite/", ListName), True
End Sub
GUID列表(如果需要的话)存储在另一个函数中
Function GUID(Foldername As String) As String
Foldername = Left(Foldername, Len(Foldername) - 1)
Foldername = RIght(Foldername, Len(Foldername) - InStrRev(Foldername, "\"))
Select Case Foldername
Case "OPSS"
GUID = "{60b2cf30-2e07-4652-a2fd-bba87fb4b368}"
Case "SSP"
GUID = "{16163312-6f3c-4a93-ba9b-37ddcc3131f6}"
Case "OPSD"
GUID = "{60b2cf30-2e07-4652-a2fd-bba87fb4b368}"
Case "MTOD"
GUID = "{1cbfd361-e41e-43a2-ac7d-fb5b5e95309f}"
Case "SSD"
GUID = "{acb234ec-f37a-4587-83ec-ddb644c5b255}"
Case "West", "Eastern", "Northeastern", "Northwestern", "Head Office"
GUID = "{09183dd4-f4e1-4a94-b881-39c8426a4c79}"
End Select
End Function
问题:
如何删除SharePoint列表的内容,以便可以用Excel中的新列表完全替换它?
我看过的其他问题:
Add data to Sharepoint 2013 list from Excel with VBA
我还有我仍在处理的添加记录部分,因此在现阶段,这非常粗糙:
Sub addnewRec_ref_to_link()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset 'tb
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
filelink = [D11].Text 'this is the array to be link from previous function
filecaption = [D8].Text
mySQL = "SELECT * FROM [sptb];"
With cnt
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=http://my.company.com/subsite/;LIST={cadce7b5-f161-4853-898c-89d8efeb4c0d};"
.Open
End With
rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic
rst.AddNew
rst.Fields("Title") = Sheets("Sheet1").Range("D4").Text
rst.Fields("FileLink") = filecaption & filelink
rst.Update
If CBool(rst.State And adStateOpen) = True Then
rst.Close
End If
Set rst = Nothing
If CBool(cnt.State And adStateOpen) = True Then
cnt.Close
End If
Set cnt = Nothing
MsgBox "Complete!"
End Sub