tbollenbach
New Member
- Joined
- Sep 19, 2013
- Messages
- 7
Good Evening All,
I am running into walls when trying to find a way to update a SharePoint list from an Excel workbook. I know how to export from excel to my SharePoint, I know how to export from the SharePoint to excel and make a linked table. The issue is I just want to click a button and have excel send the contents of a few cells to a SharePoint list. I have found at least 20 pages the show the code below but I am not able to wrap my head around where I need to update my information like my site name, list name, columns etc...
I am running excel 2013 and SharePoint 2013. Any help would be greatly appreciated.
I am running into walls when trying to find a way to update a SharePoint list from an Excel workbook. I know how to export from excel to my SharePoint, I know how to export from the SharePoint to excel and make a linked table. The issue is I just want to click a button and have excel send the contents of a few cells to a SharePoint list. I have found at least 20 pages the show the code below but I am not able to wrap my head around where I need to update my information like my site name, list name, columns etc...
Code:
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 = "<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
' Do something with response
End If
Set objXMLHTTP = Nothing
End Sub
From <http://stackoverflow.com/questions/22450717/add-and-update-single-item-in-sharepoint-list-via-vba>
I am running excel 2013 and SharePoint 2013. Any help would be greatly appreciated.