2017-04-12 67 views
2

我搜索了互聯網以找到答案,但無法找到答案。這是我的問題:將電子郵件從Outlook發送到OneNote的替代方法

我的組織在Outlook 2013收件箱大小中具有大小限制。因此,我們必須提出可能的解決方案,以便以易於管理和易於查找的方式以全面的方式保存這些電子郵件。

我聽說我們可能會自動將我們的電子郵件直接發送到OneNote 2013.我在Outlook中使用了「發送到OneNote」按鈕,但是我想知道是否有人有更好的解決方案可以自動創建如果該部分不存在,則將其命名爲電子郵件發件人的姓名,並將該電子郵件複製到新頁面。

我在我的搜索中找到的唯一VBA代碼是創建一個OneNote頁面或搜索,但是我在XML方面的知識有限並不能讓我走得更遠。

任何人都可以指向正確的方向嗎?

下面是一些我發現的代碼:

Option Explicit 

子CreateNewPage() 「連接到OneNote 2010 」要查看代碼的結果, '你要確保OneNote 2010用戶 '界面可見。

Dim OneNote As OneNote.Application 
Set OneNote = New OneNote.Application 

' Get all of the Notebook nodes. 
Dim nodes As MSXML2.IXMLDOMNodeList 
Set nodes = GetFirstOneNoteNotebookNodes(OneNote) 
If Not nodes Is Nothing Then 
    ' Get the first OneNote Notebook in the XML document. 
    Dim node As MSXML2.IXMLDOMNode 
    Set node = nodes(2) 
    Dim noteBookName As String 
    noteBookName = node.Attributes.getNamedItem("name").Text 

    ' Get the ID for the Notebook so the code can retrieve 
    ' the list of sections. 
    Dim notebookID As String 
    notebookID = node.Attributes.getNamedItem("ID").Text 

    ' Load the XML for the Sections for the Notebook requested. 
    Dim sectionsXml As String 
    OneNote.GetHierarchy notebookID, hsSections, sectionsXml, xs2013 
    ' Dim a As MSXML2.DOMDocument60 
    Dim secDoc As MSXML2.DOMDocument60 
    Set secDoc = New MSXML2.DOMDocument60 

    If secDoc.LoadXML(sectionsXml) Then 
     ' select the Section nodes 
     Dim secNodes As MSXML2.IXMLDOMNodeList 
     Debug.Print secDoc.DocumentElement.XML 
     Dim soapNS 
     soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'" 
     secDoc.SetProperty "SelectionNamespaces", soapNS 
     Set secNodes = secDoc.DocumentElement.SelectNodes("//one:Section") 

     If Not secNodes Is Nothing Then 
      ' Get the first section. 
      Dim secNode As MSXML2.IXMLDOMNode 
      Set secNode = secNodes(0) 

      Dim sectionName As String 
      sectionName = secNode.Attributes.getNamedItem("name").Text 
      Dim sectionID As String 
      sectionID = secNode.Attributes.getNamedItem("ID").Text 

      ' Create a new blank Page in the first Section 
      ' using the default format. 
      Dim newPageID As String 
      OneNote.CreateNewPage sectionID, newPageID, npsDefault 

      ' Get the contents of the page. 
      Dim outXML As String 
      OneNote.GetPageContent newPageID, outXML, piAll, xs2013 

      Dim doc As MSXML2.DOMDocument60 
      Set doc = New MSXML2.DOMDocument60 
      ' Load Page's XML into a MSXML2.DOMDocument object. 
      If doc.LoadXML(outXML) Then 
       ' Get Page Node. 
       Dim pageNode As MSXML2.IXMLDOMNode 
       soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'" 
       doc.SetProperty "SelectionNamespaces", soapNS 
       Set pageNode = doc.SelectSingleNode("//one:Page") 

       ' Find the Title element. 
       Dim titleNode As MSXML2.IXMLDOMNode 
       Set titleNode = doc.SelectSingleNode("//one:Page/one:Title/one:OE/one:T") 

       ' Get the CDataSection where OneNote store's the Title's text. 
       Dim cdataChild As MSXML2.IXMLDOMNode 
       Set cdataChild = titleNode.SelectSingleNode("text()") 

       ' Change the title in the local XML copy. 
       cdataChild.Text = "A Page Created from VBA" 
       ' Write the update to OneNote. 
       OneNote.UpdatePageContent doc.XML 

       Dim newElement As MSXML2.IXMLDOMElement 
       Dim newNode As MSXML2.IXMLDOMNode 

       ' Create Outline node. 
       Set newElement = doc.createElement("one:Outline") 
       Set newNode = pageNode.appendChild(newElement) 
       ' Create OEChildren. 
       Set newElement = doc.createElement("one:OEChildren") 
       Set newNode = newNode.appendChild(newElement) 
       ' Create OE. 
       Set newElement = doc.createElement("one:OE") 
       Set newNode = newNode.appendChild(newElement) 
       ' Create TE. 
       Set newElement = doc.createElement("one:T") 
       Set newNode = newNode.appendChild(newElement) 

       ' Add the text for the Page's content. 
       Dim cd As MSXML2.IXMLDOMCDATASection 
       Set cd = doc.createCDATASection("Is this what I need to change?") 

       newNode.appendChild cd 


       ' Update OneNote with the new content. 
       OneNote.UpdatePageContent doc.XML 

       ' Print out information about the update. 
       Debug.Print "A new page was created in " 
       Debug.Print "Section " & sectionName & " in" 
       Debug.Print "Notebook " & noteBookName & "." 
       Debug.Print "Contents of new Page:" 

       Debug.Print doc.XML 
      End If 
     Else 
      MsgBox "OneNote 2010 Section nodes not found." 
     End If 
    Else 
     MsgBox "OneNote 2010 Section XML Data failed to load." 
    End If 
Else 
    MsgBox "OneNote 2010 XML Data failed to load." 
End If 

末次

Private Function GetAttributeValueFromNode(node As MSXML2.IXMLDOMNode, attributeName As String) As String 
If node.Attributes.getNamedItem(attributeName) Is Nothing Then 
    GetAttributeValueFromNode = "Not found." 
Else 
    GetAttributeValueFromNode = node.Attributes.getNamedItem(attributeName).Text 
End If 

端功能

Private Function GetFirstOneNoteNotebookNodes(OneNote As OneNote.Application) As MSXML2.IXMLDOMNodeList 
' Get the XML that represents the OneNote notebooks available. 
Dim notebookXml As String 
' OneNote fills notebookXml with an XML document providing information 
' about what OneNote notebooks are available. 
' You want all the data and thus are providing an empty string 
' for the bstrStartNodeID parameter. 
OneNote.GetHierarchy "", hsNotebooks, notebookXml, xs2013 

' Use the MSXML Library to parse the XML. 
Dim doc As MSXML2.DOMDocument60 
Set doc = New MSXML2.DOMDocument60 

If doc.LoadXML(notebookXml) Then 
    Dim soapNS 
    soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'" 
    doc.SetProperty "SelectionNamespaces", soapNS 
    Set GetFirstOneNoteNotebookNodes = doc.DocumentElement.SelectNodes("//one:Notebook") 
    Debug.Print doc.DocumentElement.XML 

Else 
    Set GetFirstOneNoteNotebookNodes = Nothing 
End If 

端功能

感謝您的幫助。

回答

1

您是否在使用OneDrive for Business?如果是這樣,這些Microsoft Flow模板可能非常有用:https://ms.flow.microsoft.com/en-us/services/shared_onenote/onenote-business/。其中之一就是將重要的電子郵件發送到OneNote。您也可以創建自己的具有不同觸發器的流程,並指定要創建的頁面/部分的名稱。

下面是一個例子流量: enter image description here

注意 「添加動態內容」 按鈕。這使您可以指定該部分的名稱和內容。

如果您不使用O365,則可以一起使用Microsoft Graph API和OneNote REST API來實現您想要的功能。沒有VBA的例子,但還有很多其他的例子。

+0

感謝Vishaal的快速​​響應。我對任何編碼都不太熟練,儘管我通常最終會按照我最初所做的工作做,但這一次,我完全陷入了困境。 我沒有使用OneDrive for Business,只是普通的舊版Office 2013 Professional,所以我必須按照您的建議使用圖形和REST API。當你說使用圖表和REST API時,你能否給我一個例子說明你的意思? – viRg

相關問題