Import Sharepoint 2010 list data from Excel table using VBA

前端 未结 2 610
温柔的废话
温柔的废话 2021-01-03 12:52

i have learned how to gather data from a sharepoint list into Excel using VBA simple macro only.

Now i would like to do the other way around - update some list in m

相关标签:
2条回答
  • 2021-01-03 13:11

    Yes. You can use the XMLHttpRequest object provided by Microsoft's XML SDK, as well as the UpdateListItems web service provided by SharePoint to update one or more items. Add a reference to "Microsoft XML, v6.0" in the Tools -> References menu in your Visual Basic Editor, and then use something like the code below.

    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
    

    You can read more about the syntax of the UpdateListItems and how the batch XML should be structured by going here.

    0 讨论(0)
  • 2021-01-03 13:29

    enter image description here

    Not the answer to your question but maybe interesting enough. You can pull data from a Sharepoint list with PowerQuery,

    0 讨论(0)
提交回复
热议问题