哇,你在兔子洞里这么远......
好的,您正在查看的代码让您在 SharePoint 列表上查看,这可能不是最好的起点,但是这一切都是在 VBA 中完成的,这使得它非常困难。我有 .NET C# 代码来查询列表并检索具有特定值的项目。我无法进行的 VBA 转换。
public static string GetPageId(string listName, string webPath, string pageTitle)
{
string pageId = "";
IntranetLists.Lists lists = new IntranetLists.Lists();
lists.UseDefaultCredentials = true;
lists.Url = webPath + "/_vti_bin/lists.asmx";
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + pageTitle + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
XmlNode listQuery = doc.SelectSingleNode("//Query");
XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
Guid g = GetWebID(webPath);
XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());
foreach (XmlNode listItem in SPCollection.XpathQuery(items, "//sp:listitems/rs:data/z:row"))
{
XmlAttribute id = listItem.Attributes["ows_Id"];
if (id != null)
{
pageId = id.Value;
}
}
return pageId;
}
IntranetLists 是对 lists.asmx 文件的 .net Web 引用。
您必须研究如何在 VBA 中使用 lists.asmx Web 服务,
然后,您必须使用表示您要查找的列值的查询来调用 GetListItems。
<Where><Contains><FieldRef Name="Title" /><Value Type="Text">MyValue</Value></Contains></Where>
该查询的语法是CAML
那么您将不得不解析返回的 xml 以找到具有您需要的值的项目和项目字段。
任何 xpath 查询都必须添加正确的命名空间,例如
public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlToQuery.OuterXml);
XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
mg.AddNamespace("z", "#RowsetSchema");
mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");
return doc.SelectNodes(xPathQuery, mg);
}
但是我不确定您是否可以访问在您的 VBA 设置中解析 xml 的内容,因此您可能需要下载一些额外的 VBA 工具来执行此操作 - 甚至可能会被阻止。
希望这会有所帮助。