I’m trying to add an item to a Sharepoint list using VBA. I don’t want the user to have to install anything, so I’m just using Microsoft Soap Type Library. Code as follows:
Sub test()
Dim soap As MSSOAPLib.SoapClient
Dim XMLstr As String
Dim listid As String
Dim listname As String
Set soap = New SoapClient
Call soap.mssoapinit(bstrwsdlfile:="http://wss/mySharepointSite/_vti_bin/lists.asmx?wsdl")
listid = "{e285aa1a-my-list-ID-d446cdbf091e}"
listname = "thisList"
XMLstr = "<Method ID='1' Cmd='New'>" & _
"<Field Name='ID'>New</Field>" & _
"<Field Name='personID'>1337</Field>" & _
"</Method>"
soap.UpdateListItems listid, XMLstr
End Sub
I keep getting a “Type Mismatch” error on the soap.UpdateListItems line, regardless of whether I use listid or listname as the first parameter. I tried reading the WSDL to determine what type of parameter should be passed, but I don’t understand it. What should I be passing here?
EDIT: I got it to work by using Microsoft Soap Type Library 3.0 instead, changing MSSOAPLib.SoapClient->MSSOAPLib30.SoapClient30 and bstrwsdlfile->par_wsdlfile, and surrounding XMLstr with:
<Batch OnError='continue' ListVersion='1' ViewName='" & ListView & "'>
...
</Batch>
Still trying to work out a way to do this without requiring users to install MSSoap 3.0.
I solved this by sending the XML as an HTTP POST, submitted via MSXML2.XMLHTTP. Code as follows:
This requires a reference to Microsoft XML (I used “Microsoft XML, v6.0”), which AFAIK is in any standard set of VBA references. No DLL registration is needed. The function returns a DOMDocument with the result XML returned by
UpdateListItems, which you can parse to do error checking.