使用VBA从Excel更新SharePoint列表

时间:2013-10-03 06:18:12

标签: sharepoint

我希望我可以使用VBA从Excel更新共享点列表,因为我觉得使用Excel比使用Share Point更舒服。

我使用下面的代码将共享点列表数据导入Excel,工作正常

Sub ImportSharePointData()
Dim objWksheet As Worksheet
Dim CheckListObject As ListObject
Const strSPServer As String = "http://ServerName/_vti_bin"
Const LISTNAME As String = "{69D094F2-40AD-8225-26F4260A1DDB}"
Const VIEWNAME As String = "{4C6620BC-422D-9363-642F332FBF7B}"

' Worksheet in which data imports.
Set objWksheet = WksSharePointData
objWksheet.Activate

' Delete old data list if exists
Set CheckListObject = objWksheet.Range("A1").ListObject
    If CheckListObject Is Nothing Then
    Else
        objWksheet.Range("A1").ListObject.Delete
    End If

' Add a list range to the newly created worksheet and populated it with the data from the SharePoint list.
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
    Array(strSPServer, LISTNAME, VIEWNAME), False, xlGuess, Range("A1"))

End Sub

我有更好的代码来更新共享点列表,但不幸的是它根本不工作:(

Sub UpdateSharePoint()
Dim CheckListObject As ListObject
Dim objWksheet As Worksheet
Const strSPServer As String = "http://ServerName/_vti_bin"
Const LISTNAME As String = "{69D094F2-40AD-8225-26F4260A1DDB}"
Dim retUrl As String

' Worksheet in which data imports.
Set objWksheet = WksSharePointData
objWksheet.Activate

Set CheckListObject = objWksheet.Range("A1").ListObject
' Publish the table to share point
retUrl = CheckListObject.Publish(Array(strSPServer, LISTNAME), False)

End Sub

当我执行上面的代码时,我得到了最后的代码行

"运行时错误' -2147467259(80004005)': 发生意外的错误。您的数据更改无法保存"

有人可以帮助我。谢谢

0 个答案:

没有答案