我有一个共享点列表,其中包含以下字段
1)id
2)类型
3)身体
我想使用VBA功能将项目添加到以上列表中(同时在同一列的三列中)。
我想到做一个获取字典的函数,其中字典的每一行都将具有值以及将其添加到列表的字段(键)。但是我不知道这是否是更好的方法。
我正在尝试针对我的问题调整以下功能。但这是行不通的。
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
任何帮助将不胜感激。预先感谢。