Chang -
我在VBA下面寫了一個簡單的SharePoint列表SOAP查詢。我能夠在Excel中運行它並從SharePoint中提取數據。
然而,幾乎沒有人使用VBA進行SOAP調用。通常使用JavaScript,C#或Java完成。此外,大多數人已經脫離了SOAP,現在正在使用SharePoint中提供的更新的REST服務。如果你的目標是學習,那麼REST可能會更好(也更容易)。下面是一些微軟的參考,讓你開始:
例:查詢的SharePoint的UserInfo表使用VBA
Sub spListQuery()
Dim webUrl, wsdl, action, soap, xhr As XMLHTTP60
itemId = 1
listName = "UserInfo"
webUrl = "http://youserver.com" 'set to SharePoint site url
wsdl = "/_vti_bin/Lists.asmx"
action = "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
soap = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<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>" & _
"<GetListItems xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">" & _
"<listName>" & listName & "</listName>" & _
"<query><Query>" & _
"<Where><Eq><FieldRef Name=""ID""/><Value Type=""Integer"">" & itemId & "</Value></Eq></Where>" & _
"</Query></query>" & _
"<viewFields><ViewFields/></viewFields>" & _
"</GetListItems>" & _
"</soap:Body>" & _
"</soap:Envelope>"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "POST", webUrl & wsdl, False
xhr.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xhr.setRequestHeader "SOAPAction", action
xhr.Send soap
MsgBox xhr.Status & ":" & xhr.statusText & vbCrLf & xhr.responseText
End Sub
數據哇!這太棒了!非常感謝你爲我寫這篇文章。我真的在拉我的頭髮試圖弄清楚,這就像一個魅力! –