2017-04-12 17 views
2

回答を見つけるためにインターネットを調べましたが、回答が見つかりませんでした。ここに私の問題があります:OutlookからOneNoteに電子メールを送信する別の方法

私の組織は、Outlook 2013の受信ボックスのサイズにサイズ制限があります。このように、私たちは、管理しやすく、簡単に見つけやすい包括的な方法でこれらの電子メールを保存するための解決策を考案しなければなりませんでした。

私はおそらく自動的にOneNote 2013にメールを送ることができると聞いてきました。私はOutlookで「Send to 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 

End Subの

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フローテンプレートは非常に便利です: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

関連する問題