首页 > 解决方案 > 使用 Excel VBA 删除或覆盖 SharePoint 列表?

问题描述

我可以使用 Excel VBA 使用以下代码片段轻松添加创建 SharePoint 列表:

ActiveSheet.ListObjects("Table3").Publish Array( _
    "http://sitebuilder2.xyzcompany.com/operations", "test1"), False

但是,如果我使用相同的列表名称(“test1”),我会收到“运行时错误'3003':应用程序定义或对象定义的错误”,因为该列表已经存在。

是否有一种直接的方法可以使用 Excel VBA 在 SharePoint 中覆盖列表(“test1”)或删除列表(“test1”),这样我就可以在不提供新列表名称的情况下更新整个列表?

标签: excelvbasharepoint

解决方案


我能够使用此代码同步到 SharePoint 列表。

Private Sub PublishRW()
  Dim listPoint As Range
  Dim fullServerName As String
  Dim retUrl As String
  
  Set listPoint = ActiveCell.ListObject.Range(1, 1)
  fullServerName = ServerName.Value & "_vti_bin"
  
  If ListDescription.Value = "" Then
    retUrl = ActiveCell.ListObject.Publish(Array(ServerName.Value, ListName.Value), False)
  Else
    retUrl = ActiveCell.ListObject.Publish(Array(ServerName.Value, ListName.Value, ListDescription.Value), False)
  End If
  
  If retUrl <> "" Then
    ActiveCell.ListObject.Delete
    ActiveSheet.ListObjects.Add xlSrcExternal, Array(fullServerName, ListName.Value), True, xlYes, listPoint
  Else
    MsgBox "There was an error during publish, please check the server name"
  End If
  Unload ExportRWList
End Sub 

推荐阅读