Add and Update Single Item in Sharepoint List via VBA

后端 未结 1 1336
挽巷
挽巷 2021-02-06 18:12

I am trying to add and/or update single items in a sharepoint list via VBA and I found a similar question: Import Sharepoint 2010 list data from Excel table using VBA

Bu

1条回答
  •  甜味超标
    2021-02-06 19:04

    Sub Add_Item(ListName As String, SharepointUrl As String, ValueVar As String, FieldNameVar As String)
    
    Dim objXMLHTTP As MSXML2.XMLHTTP
    
    Dim strListNameOrGuid As String
    Dim strBatchXml As String
    Dim strSoapBody As String
    
    Set objXMLHTTP = New MSXML2.XMLHTTP
    
    strListNameOrGuid = ListName
    
    
    'Add New Item'
    strBatchXml = "New" + ValueVar + ""
    
    
    objXMLHTTP.Open "POST", SharepointUrl + "_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 = "" & strListNameOrGuid _
     & "" & strBatchXml & ""
    
     objXMLHTTP.send strSoapBody
    
    If objXMLHTTP.Status = 200 Then
    '   Do something with response
    End If
    
    Set objXMLHTTP = Nothing
    
    End Sub
    

    Now i got it. This is how you can Add items to a sharepoint list. FieldNameVar is the name of a Field you have to put something in (for example could this Value be 'Title') and ValueVar is the Value you put in the FieldNameVar field.

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