1
0
Fork 0
VBA-SharePoint-List-Functions/SPListLibrary.bas

40 lines
1.7 KiB
QBasic

Attribute VB_Name = "SPListLibrary"
Public Function Add_Item(ListName As String, SharepointUrl As String, ValueVar As String, FieldNameVar As String) As Integer
Dim objXMLHTTP As MSXML2.XMLHTTP
Dim strListNameOrGuid As String
Dim strBatchXml As String
Dim strSoapBody As String
Dim xmlhttpResponse As New MSXML2.DOMDocument
Dim attr As Object
Set objXMLHTTP = New MSXML2.XMLHTTP
strListNameOrGuid = ListName
strBatchXml = "<Batch OnError='Continue'><Method ID='3' Cmd='New'><Field Name='ID'>New</Field><Field Name=" + FieldNameVar + ">" + ValueVar + "</Field></Method></Batch>"
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 = "<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
Set xmlhttpResponse = objXMLHTTP.responseXML
Add_Item = CInt(xmlhttpResponse.SelectSingleNode("//UpdateListItemsResult//Results//Result//z:row").Attributes.getNamedItem("ows_ID").Text)
Else
MsgBox ("Some kind of error happened. Wut?")
Add_Item = -1
End If
Set objXMLHTTP = Nothing
End Function