使用VBA从Excel表导入Sharepoint 2010列表数据

时间:2013-11-21 09:23:39

标签: excel list vba sharepoint

我已经学会了如何使用VBA简单宏将数据从sharepoint列表收集到Excel中。

现在我想反过来 - 更新我的Excel文件中的一些列表,然后使用VBA将它们发送回sharepoint以更新列表。

是可能的,如果是的话 - 怎么样?

谢谢!

2 个答案:

答案 0 :(得分:1)

是。您可以使用Microsoft的XML SDK提供的XMLHttpRequest对象,以及SharePoint提供的UpdateListItems Web服务来更新一个或多个项目。添加对" Microsoft XML,v6.0"的引用在工具 - > Visual Basic编辑器中的引用菜单,然后使用类似下面的代码。

Dim objXMLHTTP As MSXML2.XMLHTTP

Dim strListNameOrGuid As String
Dim strBatchXml As String
Dim strSoapBody As String

Set objXMLHTTP = New MSXML2.XMLHTTP

strListNameOrGuid = "My List Name or GUID"

' Delete item with internal ID of "1"
strBatchXml = "<Batch OnError='Continue'><Method ID='1' Cmd='Delete'><Field Name='ID'>1</Field></Method></Batch>"

objXMLHTTP.Open "POST", "http://myserver/mysite/_vti_bin/Lists.asmx", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"

strSoapBody = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " _
  & "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " _
  & "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><UpdateListItems " _
  & "xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>" & strListNameOrGuid _
  & "</listName><updates>" & strBatchXml & "</updates></UpdateListItems></soap:Body></soap:Envelope>"

objXMLHTTP.send strSoapBody

If objXMLHTTP.Status = 200 Then
    ' Do something with response
End If

Set objXMLHTTP = Nothing

您可以通过here详细了解UpdateListItems的语法以及如何构建批处理XML。

答案 1 :(得分:0)

enter image description here

不是你问题的答案,但也许有趣。您可以使用PowerQuery从Sharepoint列表中提取数据,