From b75bcb88ef00855bb025b2fc6125eb015c0c8f4c Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 26 Jan 2016 15:50:13 -0700 Subject: [PATCH] Initial commit --- SPListLibrary.bas | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 SPListLibrary.bas diff --git a/SPListLibrary.bas b/SPListLibrary.bas new file mode 100644 index 0000000..d3fdff4 --- /dev/null +++ b/SPListLibrary.bas @@ -0,0 +1,39 @@ +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 = "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 + 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 + +