使用VBA在SharePoint列表中插入项目

时间:2016-01-08 11:04:37

标签: vba sharepoint

我正在尝试使用Outlook规则更新/插入SharePoint列表中的项目。我想做的是:

  1. 每当我收到来自指定收件人的邮件时,我都需要添加一个触发VBA的规则。
  2. 在VBA中,我想连接到SharePoint列表,并在其中一个共享列表中插入一行。
  3. 我在google搜索时找到了以下代码:

    Dim objXMLHTTP As MSXML2.XMLHTTP
    Dim strListNameOrGuid As String
    Dim strBatchXml As String
    Dim strSoapBody As String
    
    Sub MoveHFtoSharePointRule(Item As Outlook.MailItem)
    
    Set objXMLHTTP = New MSXML2.XMLHTTP
    
    strListNameOrGuid = "Invoicing List"
    
    '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/GetList"
    
    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><GetList " _
     & "xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>" & strListNameOrGuid _
     & "</listName></GetList></soap:Body></soap:Envelope>"
    
    MsgBox ("HERE")
    objXMLHTTP.Send strSoapBody
    
    If objXMLHTTP.Status = 200 Then
    ' Do something with response
    MsgBox ("hello")
    Else
        MsgBox ("hi")
    
    End If
    
    Set objXMLHTTP = Nothing
    
    End Sub
    

    但是我在VB的声明部分添加Dim objXMLHTTP As MSXML2.XMLHTTP的时间我的规则根本没有执行。

    请帮助以最简单的方式执行此操作。

0 个答案:

没有答案