Guest User

Untitled

a guest
Oct 24th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. Sub addItemtoList()
  2.  
  3. Dim LISTNAME As String
  4. Dim SharepointUrl As String
  5. Dim ValueVar As String
  6. Dim FieldNameVar As String
  7. Dim CurUserName As String, CurPassword As String
  8. CurUserName = "user.name"
  9. CurPassword = "password123"
  10.  
  11. LISTNAME = "SharepointlistName" 'Or Guild
  12.  
  13. SharepointUrl = "https://xxxxxxxx.sharepoint.com/sites/au/finance/xxxxxx/"
  14. ValueVar = "Testing Value Add"
  15. FieldNameVar = "'Title'"
  16.  
  17. Dim objXMLHTTP As MSXML2.XMLHTTP
  18.  
  19. Dim strListNameOrGuid As String
  20. Dim strBatchXml As String
  21. Dim strSoapBody As String
  22.  
  23. Set objXMLHTTP = New MSXML2.XMLHTTP
  24.  
  25. strListNameOrGuid = LISTNAME
  26.  
  27.  
  28. 'Add New Item'
  29. strBatchXml = "<Batch OnError='Continue'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name=" + FieldNameVar + ">" + ValueVar + "</Field></Method></Batch>"
  30.  
  31. objXMLHTTP.Open "POST", SharepointUrl + "_vti_bin/Lists.asmx", False, CurUserName, CurPassword
  32. objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
  33. objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
  34.  
  35. strSoapBody = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " _
  36. & "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " _
  37. & "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><UpdateListItems " _
  38. & "xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>" & strListNameOrGuid _
  39. & "</listName><updates>" & strBatchXml & "</updates></UpdateListItems></soap:Body></soap:Envelope>"
  40.  
  41. objXMLHTTP.send strSoapBody
  42.  
  43. If objXMLHTTP.Status = 200 Then
  44. ' Do something with response
  45. End If
  46.  
  47. Set objXMLHTTP = Nothing
  48.  
  49. End Sub
Add Comment
Please, Sign In to add comment